DISCLAIMER: this post is older than one year and may not be up to date with latest WordPress version.

In blogging, it is useful to be able to display your most popular posts. There’s WordPress plugins to do that, but you don’t need it: This code will display your most popular posts, accordoing to the comments count, without requiring you to use a plugin.

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");

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

Thanks to Neil Skoglund for this nice piece of code!



  1. Since WP 2.9 you can do that by only adding the the query “orderby=comment_count” and you’re good to go :)

  2. Still awesome! Thanks for posting.

Leave a Comment

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