How to get custom post category in wordpress

I have custom post “product” in WordPress admin panel to add products and also added category in that custom post.While showing that custom post on front-end how to show category of that custom post.

Here the_category() function of WordPress doesn’t work because that work only for default category not for custom post category.

Here’s my code to fetch category of custom post :-


< ?php

$terms = get_the_terms( $post->ID , 'taxonomyname' );

foreach ( $terms as $term ) {

echo $term->name;

}

?>

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s