wp_query custom post type with conditional terms
-
When I use the following wp_query loop to query for terms attached to the custom post type, I only get the last else content (“Thats all”). What am I doing wrong? The sidebar templates I’m calling each contain content that corresponds to each specific term. Any help that could point me in the right direction will be greatly appreciated, thanks! It’s driving me nuts!
<?php $the_query = new WP_Query( array( 'post_type' => 'speakers', 'orderby'=>'title', 'order'=>'ASC' )); ?> <?php if ( $the_query->have_posts() ) : while ( $the_query->have_posts() ) : $the_query->the_post(); if ( has_term( 'embedding' ) ) { echo get_sidebar('speakerslist-embedding'); } elseif ( has_term( 'reorganizing' ) ) { echo get_sidebar('speakerslist-reorganizing'); } elseif ( has_term( 'accountability' ) ) { echo get_sidebar('speakerslist-accountability'); } else { // catch-all for everything else (archives, searches, 404s, etc) echo "<p>That's all.</p>"; } // That's all, folks endwhile; ?> <?php endif; ?> <?php wp_reset_query(); ?>
Viewing 2 replies - 1 through 2 (of 2 total)
Viewing 2 replies - 1 through 2 (of 2 total)
- The topic ‘wp_query custom post type with conditional terms’ is closed to new replies.