Home » Wordpress » How to display selected category names of custom post type in wordpress

Here is code snippet to display selected category names of custom post type in wordpress.

To get the categories of a custom post type you have call get_the_terms() and setup the registered category name like this

<?php
$terms = get_the_terms( $post->ID , 'myposttype_category' );
foreach ( $terms as $term ) {
  echo $term->name;
}
?>

Array ( [0] => Wordpress, Wordpress Freelancer )

Leave a comment

0 Comments.

Leave a Reply

You must be logged in to post a comment.