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

1 Answer 1

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