get post taxonomy category name code example
Example 1: 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 2: get taxonomy name in singhle post
// RETRIVE TERM SLUG ( for single.php or template-part )
$terms = get_the_terms( $post->ID, 'your-taxonomy' );
if ( !empty( $terms ) ){
// get the first term
$term = array_shift( $terms );
echo $term->slug;
}