Get and Display Parent Taxonomy in Custom Post Type

Your in a Custom Post Type (ie: Lesson) and in that lesson template, you want to display the name of the taxonomy that it’s in – let’s say a Module.

Just the name of the parent taxonomy

1
2
3
4
5
6
7
8
// this one works to display the name of the current posts taxonomy title
add_action( 'genesis_before_sidebar_widget_area', 'parent_module_link' );
function parent_module_link () {
	$terms = get_the_terms( $post->ID , 'module' );
		foreach ( $terms as $term ) {
		echo '<h4>' . $term->name . '</h4>';
		}
	}

The name of the parent taxonomy linking back to its archive page

1
2
3
4
5
6
7
8
9
10
11
//Yay - this will display a link and name of the parent module
add_action( 'genesis_before_sidebar_widget_area', 'parent_module_link' );
function parent_module_link () {
	$terms = get_the_terms( $post->ID , 'module' ); 
	                foreach ( $terms as $term ) {
	                    $term_link = get_term_link( $term, 'module' );
	                    if( is_wp_error( $term_link ) )
	                    continue;
	                echo '<h4><a href="' . $term_link . '">' . $term->name . '</a></h4>';
	                } 
	               }