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?

2 Answers
2

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;
}

Tags:

Leave a Reply

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