Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I need to get any post category id from the post id(Not for current) Post. How can i ?

Thanks

share|improve this question
    
i used this code . but i got i array is blank global $post; $category_detail=get_the_category( $post->ID ); –  user2307052 Mar 18 at 7:48

2 Answers 2

up vote 2 down vote accepted

You can try this code for getting category id from post id:

global $post;
$category_detail=get_the_category( $post->ID );
share|improve this answer

Take a look at wp_get_post_categories function. It returns an array of categories' ID for specific post.

$post_categories = wp_get_post_categories( $post_id );
share|improve this answer

Your Answer

 
discard

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.