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

Let's say I have a custom post type (e.g. product) and a custom taxonomy (e.g. prod_cat).
What I need to do is to get all my custom taxonomy terms associated with an object of my custom post type.
Here is how I do it inside the loop.

$terms = wp_get_object_terms(get_the_ID(),'prod_cat', array('fields'=>'slugs'));

But it's not working. It returns an empty array.

share|improve this question

According to the function definition, wp_get_object_terms() throws an error if it can't find your taxonomy - and returns an empty array if there aren't any taxonomy terms attached to that post. Have you made sure you've assigned a prod_cat to the custom post you're looking at?

share|improve this answer
Yes, I'm sure I have. – Hamed Momeni Sep 1 '12 at 15:55

This may help: http://codex.wordpress.org/Function_Reference/get_terms

Have you tried something like this:

foreach ( get_terms( 'prod_cat' ) as $term ) {
    // Insert some code here
share|improve this answer
thanks for the edit. Much prettier ;) – TomHarrigan Sep 1 '12 at 1:30
I don't understand what are you saying? – Hamed Momeni Sep 1 '12 at 15:55

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.