I'm using WordPress's get_terms
to return an array of WP_Term
objects containing the term_id, name, slug, etc. for the child terms of a given taxonomy. I've saved this array to $tax_terms
. I have a different array—$active_filters
—containing just the slugs of terms that match certain taxonomy terms; for instance, from a var_dump
of $active_filters
:
array (size=3)
0 => string 'term-1' (length=6)
1 => string 'term-2' (length=6)
2 => string 'term-3' (length=6)
I'm wondering if there's a way I can run a foreach
that will compare this array of term slugs to those in the array returned by get_terms
and return the name
for any matched slug? So, the example above would output "Term 1", "Term 2", "Term 3". I've tried using array_search
but to no avail, thus far. Any assistance is greatly appreciated.