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 !
You can easily sort by native post fields, so try something like this:
$posts = get_posts( array(
'numberposts' => 10,
'orderby' => 'comment_count',
) );
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>
make a try on WordPress Popular Posts Plugin. In this Plugin we having the option to sort with comment for popular post.:)