With the new WP_Date_Query in WordPress 3.7+ it’s easy to list most commented posts within a certain time span from a specific category.
Note: this example lists most commented articles posted within X date, not looking for most amount of comments within that time span among all articles.
We’re using WP_Query to list the posts here.
<?php $popular = new WP_Query( array( 'post_type' => array( 'post' ), 'showposts' => 6, 'cat' => 'MyCategory', 'ignore_sticky_posts' => true, 'orderby' => 'comment_count', 'order' => 'dsc', 'date_query' => array( array( 'after' => '1 week ago', ), ), ) ); ?> <?php while ( $popular->have_posts() ): $popular->the_post(); ?> <?php the_title(); ?> <?php endwhile; ?>
A whole lot simpler than before. 1 day ago, 1 week ago, 2 weeks ago, 1 month ago, 1 year ago, all time and so on – your choice. Note: for all time, the value would simply be 0.
Thank’s
Thanks, Worked !!!
see it :
https://mohandesibargh.com
Thanks Man.
Great
check here
https://poweren.ir
it works
Thank you man
HI, how to get only posts with 1 or more comments?
I searched high and low for something like this, thanks for sharing!
oh, finally I found the answer.
Thanks, bro!
=D
Thanks for your code. Before this, i’m using this code.
Popular Posts by Most Commented
get_results(”
SELECT comment_count, ID, post_title
FROM $wpdb->posts ORDER BY comment_count DESC LIMIT 0 , 20
“);
foreach ($result as $post) {
setup_postdata($post);
$postid = $post->ID;
$title = $post->post_title;
$commentcount = $post->comment_count;
if ($commentcount != 0) { ?>
<a href="”>
[]
But i think your code more neat, elegant and easy to understand. Peace.
This is so great! Awesome Article and very helpful !!!
thank you for nice theme and useful wp post.
well if put your post feed at least in code page 🙂
Added 😉