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 need to get any post category id from the post id(Not for current) Post. How can i ?


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 '14 at 7:48
up vote 4 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


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.