get category name info in custom post type single post page in wordpress
<?php
global $post;
$terms = get_the_terms( $post->ID, 'product_cat' );
foreach ($terms as $term) {
$product_cat_id = $term->term_id;
$category_link = get_category_link( $product_cat_id );
if( $term = get_term_by( 'id', $product_cat_id, 'product_cat' ) ){
$cat_name=$term->name;
}
break;
}
global $post;
$terms = get_the_terms( $post->ID, 'product_cat' );
foreach ($terms as $term) {
$product_cat_id = $term->term_id;
$category_link = get_category_link( $product_cat_id );
if( $term = get_term_by( 'id', $product_cat_id, 'product_cat' ) ){
$cat_name=$term->name;
}
break;
}
Comments
Post a Comment