wordpress get category by post id code example
Example 1: how to get category from post id
get_the_category($post->ID)
Example 2: wordpress get post category name
<?php
$categories = get_the_category();
if ( ! empty( $categories ) ) {
echo esc_html( $categories[0]->name ); // Show first item of category
}
?>
Example 3: wordpress display post categories
<?php the_terms( $post->ID, 'topics', 'Topics: ', ', ', ' ' ); ?>