How do I set an orderby on a custom taxonomy template?
-
I have a custom taxonomy template called taxonomy-series.php.
The loop in this template is:
<?php if (have_posts()) : ?> <div class="list-group mb-5"> <?php while (have_posts()) : the_post(); ?> <?php get_template_part( 'includes/listgroup' ); ?> <?php endwhile; ?> </div> <?php endif; ?>
I need to change the default loop so that the list of posts assigned to the taxonomy terms are ordered by the custom field called series_order_num.
I tried this, but it completely ignored the taxonomy term and I don’t know how to include the term so that whatever term is assigned to the page is included:
<?php $series_query = new WP_Query(array( 'post_type' => 'post', 'posts_per_page' => -1, 'meta_key' => 'series_part_num', 'orderby' => 'meta_value', 'order' => 'DESC' )); ?> <?php if( $series_query->have_posts() ): ?> <div class="list-group mb-5"> <?php while( $$series_query->have_posts() ) : $series_query->the_post(); ?> <?php get_template_part( 'includes/listgroup' ); ?> <?php endwhile; ?> </div> <?php endif; ?> <?php wp_reset_query(); // Restore global post data stomped by the_post(). ?>
I’m clearly missing something somewhere and need another pair of eyes.
Viewing 1 replies (of 1 total)
Viewing 1 replies (of 1 total)
- The topic ‘How do I set an orderby on a custom taxonomy template?’ is closed to new replies.