Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

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
add comment

1 Answer 1

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
add comment

Your Answer

 
discard

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.