You can try this code for getting category id from post id:
global $post;
$category_detail=get_the_category( $post->ID );
Related Posts:
- Get Posts Under Custom Taxonomy
- How to add category to: ‘wp-admin/post-new.php’?
- Use category base slug in posts’ permalink
- Setting Custom Sort Order of Posts within a Category
- Different number of posts in each category
- Display the latest post from a category in a page
- How to show list of posts by author and category?
- Exclude posts that only have the ‘Uncategorized’ category [duplicate]
- Getting Position of a post in a category
- Display only posts from a specific parent category
- get_the_term_list by hierarchy order
- How to change the layout and styling of posts according to their category in WordPress?
- display sub categories assoccited with each post in a category archive page
- How can I specify a category post on my home page
- Use template of parent category for single post sub-categories
- How to search only by post title and category?
- Permalink Settings: optional settings doesn’t apply to editor
- Divide Loop Into Days & Categories
- Different template for posts of all subcategories of category
- I want to show category in the post title , how can I do
- Mark menu item as current-menu-item for category
- Random post category URL
- How to set up multiple taxonomies for groups of posts
- How can i sort the categories by ID
- Display posts in three columns by category
- Add ajax load more function using WP API
- Deleted category by mistake, all posts now have categorized category. Can i revert that?
- How to display category from recent posts?
- Properly display posts on homepage
- Display post X of Y in category
- Exclude category from
- Post page to display specific category
- WordPress Multisite – Create Default Post and New Category On New Site Install
- how to show single post in a custom template
- Using ajax on editing a category edit page?
- Disable sticky option for specific categories
- date issue with category post retrival
- How to make multiple sections in home pulling posts category wise?
- Excluding posts not working
- How to get subcategories from category slug?
- Remove current category from post but display all others
- Showing categories and subcategories with posts
- Change default category when I publish a post
- Loop doesn’t exclude the specified category in home page
- Post Image not displaying in category view
- How do I include the category next to the title of a post?
- Migrate posts from category and sub-category via SQL
- Parent category / child category posts
- Posts Missing in Dashboard after update
- How to get post with slug and exclude categories
- Unable to differentiate between two categories under custom post type on single.php
- Exclude post category in a blog page
- Retrieving posts by their date and category
- Are post, page and category IDs unique to each other?
- Static pages not working
- WP_Query of Category Not Showing First Post
- WordPress displays post on subcategory only
- How to make posts being uncategorized
- How to display a single(current) post from a category
- displaying the categories post
- What’s a theme that properly handles previews of different types of posts?
- Categories Listing and Highlighting current category item
- How to add content above footer in posts from specific category
- WordPress – When visiting a `single post/ single.php` my category menu item link becomes active
- Author post count in category
- How to Create another Page Category like the “Post” and “Pages”
- How to create a button to filter posts (list) by meta value
- Is there a way to save different data when USER interacts with the same POST?
- How to display particular categorie’s post which associated to specific user?
- Display Specific Categories posts on the home page
- show only one category and filter by tag
- Automatic Table of contents with categories and posts
- Code to display random ordered posts in Categories across pages [duplicate]
- AJAX load more posts not using correct category and repeating the same few posts
- Category posts show on local install, they do not show on live server
- How can I exclude only a specific sub category post from category display?
- how to print total number of posts filtered by category?
- Need help with hiding an image within a post in a category
- WordPress not showing recent posts
- How to filter out post from a category not its subcategory in wordpress dashboard
- Add category information beneath post?
- How can I display a specific number of post in a category via a url
- Newly created category does not show category
- How to pass multiple checkbox values to wordpress query?
- Sort post by category using HTML Select tag
- Show a Category Specific Info Box
- Display the first post’s comments of category in comments.php template
- How to filter categories of a post
- Exclude a ‘portfolio’ custom category?
- List posts related to category on a div [closed]
- how to show all post with its contents
- wordpress show category link instead of post link [closed]
- CSS – Change height of Storefront / WooCommerce product categories, but not products
- excerpt in template for specific page
- Only show posts belonging to multiple cateogries at same time
- Wrap posts from a category in HTML
- How to display my categories in a list (to a post, not the sidebar)?
- How to make category for word post_content
- wordpress category Description not allowed tag
- Site ‘Categories’: save an admin global setting with post metadata [closed]