gplana
asked on
Why get_terms function is returning an empty array ?
Hi.
I created a custom taxonomy called "forum_category" for which I created some possible values.
I'm using this simple code to see the list of terms for this taxonomy:
but print_r shows an empty array. Do you know why ? What should I do to get all the values from a taxonomy ?
Thank you.
I created a custom taxonomy called "forum_category" for which I created some possible values.
I'm using this simple code to see the list of terms for this taxonomy:
$terms = get_terms('forum_category');
print_r($terms);
but print_r shows an empty array. Do you know why ? What should I do to get all the values from a taxonomy ?
Thank you.
What's the rest of the context of that code? Where are you running it?
ASKER
Thank you for your answer.
I'm running it on a php file which is called from a template. This taxonomy is attached to a bbPress topic, which is a kind of post called 'topic'.
I'm running it on a php file which is called from a template. This taxonomy is attached to a bbPress topic, which is a kind of post called 'topic'.
But the full WordPress calls appear above it, right (e.g. wp_load(), etc)?
Without more code we're guessing a little bit here. Does anything actually have that taxonomy associated with it, and if so, do any of those actually make use of any of those values? It could be that nothing is returned because it might ignore unassociated terms.
If you know the post ID of a page which does make use of the taxonomy you can try using the_terms( ID, 'taxonomy') instead, to verify that things are appropriately associated.
If that's not helpful then the question would be:
I've used the following code for taxonomy based tag clouds before:
If you know the post ID of a page which does make use of the taxonomy you can try using the_terms( ID, 'taxonomy') instead, to verify that things are appropriately associated.
If that's not helpful then the question would be:
are you trying to display all the terms in the taxonomy, as though it were a list of ALL the categories,
or are you trying to list all the values associated with a given post?
I've used the following code for taxonomy based tag clouds before:
<?php wp_cumulus_insert(array('args' => 'smallest=8&largest=20&number=100&taxonomy='.$term->taxonomy)); ?>
This should work equally well:wp_tag_cloud( array('args' => 'smallest=8&largest=20&number=100&taxonomy=forum_category'));
Hopefully those help you figure out the root problem...
ASKER
Jason 1178: all the rest of Wordpress functions works. In fact I get no error in executing get_terms() function, just I get an empty array instead of an array with the expected values.
dcowley: Thank you so much for your help. I can provide whatever part of code you need.What I'm trying to get is the possible values for a taxonomy (the list of forum categories in my case), not the values for this taxonomy on the actual post. In fact, I don't have actual post because this code is executing on a template that shows the list of posts (list of topics of a bbForum to be exact). I added this taxonomy to make user be able to select for which categories he wants to see the topics. Anyway, I will try the two functions you said and let you know, but get_terms is supposed to return an array with all the values for a taxonomy, isn't it ?
dcowley: Thank you so much for your help. I can provide whatever part of code you need.What I'm trying to get is the possible values for a taxonomy (the list of forum categories in my case), not the values for this taxonomy on the actual post. In fact, I don't have actual post because this code is executing on a template that shows the list of posts (list of topics of a bbForum to be exact). I added this taxonomy to make user be able to select for which categories he wants to see the topics. Anyway, I will try the two functions you said and let you know, but get_terms is supposed to return an array with all the values for a taxonomy, isn't it ?
ASKER
Hi again.
I tryied to add this function:
It looks like this taxonomy is not found. Could the "_" sign on the name be a problem ?
I tryied to add this function:
wp_tag_cloud( array('args' => 'smallest=8&largest=20&number=100&taxonomy=forum_category'));
but no results are shown.It looks like this taxonomy is not found. Could the "_" sign on the name be a problem ?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Wow ! It works exactly as you said !!!
Thank you so much. I didn't know this "hide_empty" parameter. You save me a lot of hours of investigation.
Thank you, thank you so much.
Thank you so much. I didn't know this "hide_empty" parameter. You save me a lot of hours of investigation.
Thank you, thank you so much.
Nice work, dcowley!