I want to get category id from post id of a custom type.
I have the post id, but I can’t get it’s category id.

I have used so many codes but it doesn’t work, may be due to custom post type.

$category = get_the_category( $post->ID );

Any suggestions?

3 s
3

wp_get_post_categories can only get POST categories not a custom post’s categories, try this instead:

$category = get_the_terms( $post->ID, 'custom-taxonomy-here' );     
foreach ( $category as $cat){
   echo $cat->name;
}

Check this link

Leave a Reply

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