WordPress hack: Get popular posts by comments count

Simply paste the following code where you want to display your most popular posts to be displayed:

$pop = $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>
foreach($pop as $post) : ?>
<li> <?php echo $post->post_title; ?> </li>
<?php endforeach; ?>
</ul>

Thanks to Neil Skoglund for this nice piece of code!

Looking for WordPress hosting? Try WP Web Host. Prices starts at $5/month and you can try it for free!

WordPress hack: Get popular posts by comments count

Leave a Reply

Your email address will not be published. Required fields are marked *