I’m trying to retrieve all the categories which are related to a specific post, using the wp_get_post_categories() function. The problem is that it is a custom post type, so I tried sending it in the $args array :

wp_get_post_categories($id,array('post_type'=>'product'));

but that returned an empty array as well.
What is the correct way of doing it?

2 Answers
2

Are you sure it a category, and not a custom taxonomy?

If it is a category try:

var_dump( wp_get_post_categories( $id ) );

or its equivalent since category is a taxonomy:

var_dump( wp_get_object_terms( $id, 'category' ) );

Leave a Reply

Your email address will not be published. Required fields are marked *