how to get custom post type category name in wordpress code example
Example 1: wordpress get post category name
<?php
$categories = get_the_category();
if ( ! empty( $categories ) ) {
echo esc_html( $categories[0]->name );
}
?>
Example 2: wp+create custom post type and category
add_action( 'init', 'create_news' );
function create_news ()
{
register_post_type( 'ecommerces',
array(
'labels' => array(
'name' => __( 'Ecommerces' ),
'singular_name' => __( 'Ecommerce' )
),
'public' => true,
'supports' => array ('title', 'editor', 'thumbnail')
)
);
register_taxonomy(
'ecommerce_cat',
'ecommerces',
array(
'labels' => array(
'name' => 'Ecommerce Categories',
'add_new_item' => 'Add New Ecommerce Category',
'new_item_name' => "New Ecommerce Category"
),
'show_ui' => true,
'show_tagcloud' => false,
'hierarchical' => true,
'hasArchive' => true
)
);
}
if ( function_exists( 'add_theme_support' ) ) {
add_theme_support( 'post-thumbnails' );
set_post_thumbnail_size( 100, 100, true );
}
?>