0

I want list the popular posts.popular post is defined by number of comments.If number of comment is high it will consider as popular.

How can i do this !

2

You can easily sort by native post fields, so try something like this:

$posts  = get_posts( array(
                 'numberposts' => 10,
                 'orderby' => 'comment_count',
                 ) );
0
0

Copy paste the following code, where you want to display the popular posts

$popular = $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($popular as $posts) : ?>
<li> <?php echo $posts->post_title; ?> </li>
<?php endforeach; ?>
</ul>
0

make a try on WordPress Popular Posts Plugin. In this Plugin we having the option to sort with comment for popular post.:)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.