WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

The code below is the 2nd of 4 loops in "page-balls.php". Everything else is working correctly.

I'm trying to display a tennis ball graphic if the post being retrieved has a the term "tennis-ball" term. It's not working. Is this because the PAGE does not have the term TENNIS-BALL?

How can I make this work correctly?

$args = array (
'post_type' => 'balls',
'orderby' => 'menu_order',
'order' => 'ASC'                
) ;

$myQuery = new WP_Query( $args ) ;

<?php if ($myQuery->have_posts()) : while ($myQuery->have_posts()) : $myQuery->the_post(); ?>

<?php if(is_tax( 'ball-types', 'tennis-ball' )) : ?> 
<?php else : ?>
<?php endif ; ?>

<?php endif ; ?>

<?php wp_reset_postdata() ; ?>
share|improve this question
up vote 3 down vote accepted

The codex on is_tax:

This Conditional Tag checks if a custom taxonomy archive page is being displayed.

That is not the condition you want to check for.

Take a look at the has_term function and use it like so:

if( has_term( 'tennis-ball', 'ball-types', $post->ID ) ) { 
} else {

And as an aside, remove some of the <?php opening and closing tags. They serve no purpose and simply make your code less legible.

share|improve this answer
Thanks for the help Johanne. Appreciated. Re. the aside... Actually, I prefer writing my PHP this way. Once there's a lot of HTML in there, I find it much easier to read by placing the PHP in individual blocks. It's just a personal pref. – Wicky Apr 30 '13 at 16:38
Obviously, @Wicky, you may write your code as you see fit - who am I to say what works for you personally. Should you ever have to work in cooperation with other developers though, I promise you this practice will become an issue. Also, ideally logic and markup don't mix. I realize that's not always possible, though. Anyhoo, if the main aspect of this answer solved your immediate problem (which I am quite confident it did), be so kind as to tick the checkmark to the left of the answer, such that others that have a similar issue can tell it is resolved. – Johannes Pille Apr 30 '13 at 17:25

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.