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.

This lists the posts in my custom taxonomy template page:

<?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>

How can I order those posts by comment count?

share|improve this question

2 Answers 2

WP Query has a comment_count parameter since 2.9.

So:

query_posts(array('orderby' => 'comment_count', 'posts_per_page' => '10'));
if ( have_posts() ) : while ( have_posts() ) : the_post();
share|improve this answer
    
FYI: You have curly quotes in your code sample. –  Mark Duncan Jul 22 '11 at 9:15
    
Strange, thanks, fixed. –  Wyck Jul 22 '11 at 13:55
    
I tried this, but it listed posts that had nothing to do with the particular custom taxonomy. –  Carson Jul 22 '11 at 19:30
1  
That was not really your question. –  Wyck Jul 23 '11 at 0:23
up vote 1 down vote accepted

A friend helped me with a solution that I could place in my functions.php file:

add_filter( 'pre_get_posts', 'my_pre_get_posts' );

function my_pre_get_posts( $query ) {

    if ( is_tax( 'locations' ) && empty( $query->query_vars['suppress_filters'] ) )
        $query->set( 'orderby', 'comment_count' );

    return $query;
}
share|improve this answer

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.