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

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 :


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

share|improve this question
up vote 1 down vote accepted

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' ) );
share|improve this answer

Your post-type product has probably it's own "category" taxonomy. Try:

wp_get_object_terms( $id, '<your-custom-product-category-taxonomy>', array( 'fields' => 'ids' ) );
share|improve this answer

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.