Get Category name from Post ID Get Category name from Post ID wordpress wordpress

Get Category name from Post ID


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

$category_detail=get_the_category('4');//$post->IDforeach($category_detail as $cd){echo $cd->cat_name;}

get_the_category


echo '<p>'. get_the_category( $id )[0]->name .'</p>';

is what you maybe looking for.


doesn't

<?php get_the_category( $id ) ?>

do just that, inside the loop?

For outside:

<?phpglobal $post;$categories = get_the_category($post->ID);var_dump($categories);?>