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.

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?

  • Yes, I'm sure I have. – Hamed Momeni Sep 1 '12 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
}
  • I don't understand what are you saying? – Hamed Momeni Sep 1 '12 at 15:55

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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