Display Popular Posts by Comment Count

The following snippet can be used to show the posts with the highest number of comments. It displays the posts in a list, but could easily be customized.


<?php $popular_posts = $wpdb->get_results("SELECT id, post_title, comment_count FROM {$wpdb->prefix}posts WHERE post_type='post' ORDER BY comment_count DESC LIMIT 10"); ?>

<ul>
<?php foreach($popular_posts as $post) : ?>
<li> <?php echo $post->post_title; ?> </li>
<?php endforeach; ?>
</ul>

Source

Leave a Comment

*