For a custom post type, use get_the_terms()
instead:
<?php $post_terms = get_the_terms( get_the_ID(), 'your-taxonomy' ); ?>
<p> Category: <?php echo $post_terms[0]->name; ?></p>
Much like the results from get_the_category
, the returned value of get_the_terms()
is an array of term objects for the taxonomy that you specify when calling the function. In the example code, that is “your-taxonomy”.
This sample code will only display the first term if multiple terms are assigned to a post. That is the ‘zero position’ in the array. Any subsequent terms would be returned in $post_terms[1]
, $post_terms[2]
, etc
https://developer.wordpress.org/reference/functions/get_the_terms/