I may be going about this all wrong but I'm trying to use get terms to get all of the terms that exist in every taxonomy.

I think this might be a php question.

get_terms allows you to specify which taxonomies it gets terms from in array like this...

get_terms( array(post_tag, category, nav_menu, link_category, post_format), $args )

That works, but I'm writing a plugin and if people have custom taxonomies manually entering the array will not work. So I figured the solution would be to use get taxonomies to generate that array. The problem is, it comes back as an associatave array and I need a simple array. So I did this...

$myarray = 'array('. implode(', ',get_taxonomies('','names')) .')';

which, if I echo $myarray, returns: array(category, post_tag, nav_menu, link_category, post_format)

perfect; That's exactly what I have manually entered. now I should be able to stick $myarray in get_get terms where I have it manually entered and it should get everything. Nope. It doesn't like it.

Here's the entire snippet of code, along with a pic of what get's echoed out. You can see that $myarray is exactly the same as what's in the working get_terms but it's breaking the second get_terms.

$myarray = 'array('. implode(', ',get_taxonomies('','names')) .')';

echo $myarray . '<br/>';
echo 'array(category, post_tag, nav_menu, link_category, post_format) <br/><br/>';

print_r(get_terms( array(post_tag, category, nav_menu, link_category, post_format), $args )); echo '<br /><br />';
print_r(get_terms( $myarray , $args )); echo '<br /><br />';

Result: https://i.sstatic.net/4aE8C.jpg


1 Answer 1


Ok, so I don't know what I was doing wrong because I tried this before and couldn't get it to work but I ended up using array_values() after a couple of people recommended it in another thread.

I finally ended up writing it like this:

get_terms( array_values((get_taxonomies('','names'))) , $args );

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.