1

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?

1 Answer 1

2

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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