How to show custom taxonomy in single post

Array of requested term objects, or empty array, if no terms found. WP_Error if $taxonomy does not exist. See is_wp_error() for more information.

Examples

Return a list of all ‘product’ taxonomy terms that are applied to $post:

$product_terms = wp_get_object_terms( $post->ID,  'product' );
if ( ! empty( $product_terms ) ) {
	if ( ! is_wp_error( $product_terms ) ) {
		echo '<ul>';
			foreach( $product_terms as $term ) {
				echo '<li><a href="' . get_term_link( $term->slug, 'product' ) . '">' . esc_html( $term->name ) . '</a></li>'; 
			}
		echo '</ul>';
	}
}


Leave a Reply