Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I have this unusual requirement from my client that I need to accommodate. They want to be able to view the posts with the largest number of comments first.

At first I thought using a custom select query would do the trick. I had to write a subquery to but was able to use a custom select query to implement the functionality. Well, it didn't take me too long to realize that suddenly the WP Page Numbers plugin stopped working. Looking at the source code for the plugin I realized it's relying on the WP_Query object having been populated in order to figure out the page numbers and navigation stuff.

I can't think of a way to use the WP_Query class to do the kinds of sorting I need to do. At the same time, I don't want to have to implement my own pagination functionality because my client (and I) really love the WP Page Numbers plugin.

Before I go down the path of extending the WP_Query class as Mike suggested in this post, I just wanted to reach out to everyone with similar experiences and ask if there is any alternatives. Thanks!

share|improve this question
3  
What's wrong with this? query_posts( 'orderby=comment_count' ); –  Lynne Feb 4 '11 at 20:03
    
OMG, you're kidding!!! Let me give it a shot. –  PFrank Feb 4 '11 at 20:18
    
Let me know if it works... I was using it for a while for my own client who later changed their mind because they realized that that every new post that becomes popular will have to gain that many comments to get to the top of the page :p –  Lynne Feb 4 '11 at 20:57
    
It worked! Thank you!! –  PFrank Feb 5 '11 at 12:03
add comment

1 Answer

Looks like Lynne has you headed in the right direction PFrank. Check out this page in the WordPress Codex for more info on sorting queries and sorting by 'comment_count'.

http://codex.wordpress.org/Function_Reference/query_posts#Order_.26_Orderby_Parameters

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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