• roadtrip

    (@roadtrip)


    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)
  • Josh

    (@josh401)

    Please read the codex for has_term().

    You’re missing the taxonomy argument.

    Thread Starter roadtrip

    (@roadtrip)

    Getting closer. I added the taxonomy argument and got the speakers list to display, but they all display, instead of according to term associated with each. Here’s the rev:

    <?php
                    $the_query = new WP_Query( array(
                        'post_type' => 'speakers',
                        'taxonomy' => 'event-names',
                         'orderby'=>'title',
                         'order'=>'ASC'
                    ));
    
                    ?>
    
                    <?php if ( $the_query->have_posts() ) : while ( $the_query->have_posts() ) : $the_query->the_post(); 
    
                        if ( has_term( 'embedding', 'event-names' ) ) {
    
                            echo get_sidebar('embedding'); 
    
                        } elseif ( has_term( 'reorganizing', 'event-names' ) ) {
    
                            echo get_sidebar('reorganizing'); 
    
                        } elseif ( has_term( 'accountability', 'event-names' ) ) {
    
                            echo get_sidebar('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)
  • The topic ‘wp_query custom post type with conditional terms’ is closed to new replies.