0

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.

2 Answers 2

0

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?

1
  • Yes, I'm sure I have.
    – 2hamed
    Sep 1, 2012 at 15:55
0

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
}
1
  • I don't understand what are you saying?
    – 2hamed
    Sep 1, 2012 at 15:55

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.