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 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: http://i.imgur.com/tMJUmaz.jpg

share|improve this question
up vote 0 down vote accepted

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 );
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.