Get Category name from Post ID


Is it possible to get the category name of a category given the Post ID, the following code works to get the Category Id, but how can I get the name?

<?php $post_categories = wp_get_post_categories( 4 ); echo $post_categories[0]?>



here you go get_the_category( $post->ID ); will return the array of categories of that post you need to loop through the array

foreach($category_detail as $cd){
echo $cd->cat_name;


Answered By – M Khalid Junaid

This Answer collected from stackoverflow, is licensed under cc by-sa 2.5 , cc by-sa 3.0 and cc by-sa 4.0

Leave a Reply

(*) Required, Your email will not be published