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

I am currently running the below wordpress php and it is creating a list for me.

$term = get_term_by( 'id', $ptc, $taxonomy );
echo '<li><a href="'. home_url() .'/taxon/'. $pt->slug .'/' .  $term->slug . '">' . $term->name . '</a> </li>';

However, I need it to check to see if $term is in_array $product_terms so I tried:

$term = get_term_by( 'id', $ptc, $taxonomy );
                if(in_array($term, $product_terms)){ 
                    echo '<li class="current-cat"><a href="'. home_url() .'/taxon/'. $pt->slug .'/' .  $term->slug . '">' . $term->name . '</a> </li>';
                } else {
                    echo '<li><a href="'. home_url() .'/taxon/'. $pt->slug .'/' .  $term->slug . '">' . $term->name . '</a> </li>';

But it still returns none with the extra class even though I know one of them is in the array... Any ideas how to make this work?

share|improve this question
up vote 2 down vote accepted

It depends on what kind of type are the values from your $product_terms array.

If you have strings there, like term slugs, then you probably want to check if $term->slug exists.

If you have objects, then make sure the array is indexed, and not associative. For associative arrays use array_key_exists() instead.

share|improve this answer

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.