Site icon SumTips

Most Commented WordPress Posts in the last 30 days

This code will return an unordered list of most commented WordPress posts in the last 30 days. You can easily customize it as per your preference.

<ul>
<?php
function filter_where($where = '') {

$where .= " AND post_date > '" . date('Y-m-d', strtotime('-30 days')) . "'";
return $where;
}

add_filter('posts_where', 'filter_where');

query_posts('post_type=post&posts_per_page=5&orderby=comment_count&order=DESC');

while ( have_posts() ): the_post(); ?>
<li><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></li>
<?php

endwhile;
wp_reset_query();
remove_filter( 'posts_where', 'filter_where' );
?>
</ul>
Exit mobile version