Display a list of custom taxonomy terms and their posts
-
I’m trying to display some tabbed content where each tab is a taxonomy term. And under each tab there would be a loop displaying posts from that taxonomy term.
Right now I can only display posts from a specific taxonomy term. In this case “Hotels”.
How do I modify my code so that all terms would be displayed with their posts underneath?
Hotels
– First hotel post
– Second hotel post
Cafes
– First cafe post
– Second cafe post<?php $args = array( 'post_type' => 'testimonials', 'post_status' => 'publish', 'tax_query' => array( array( 'taxonomy' => 'testimonial_taxonomies', 'field' => 'slug', 'terms' => 'hotels' ) ) ); $testimonials = new WP_Query( $args ); if( $testimonials->have_posts() ) : ?> <?php while( $testimonials->have_posts() ) : $testimonials->the_post(); ?> <?php the_title( '<h3>', '</h3>' ); ?> <?php the_excerpt(); ?> <?php endwhile; wp_reset_postdata(); ?> <?php else : ?> <? endif;?>
Viewing 1 replies (of 1 total)
Viewing 1 replies (of 1 total)
- The topic ‘Display a list of custom taxonomy terms and their posts’ is closed to new replies.