Add Custom Taxonomy Post Meta Terms to Custom Post Type in Genesis WordPress

To add in the post meta of  custom taxonomy terms into custom post types in Genesis WordPress theme you need to create a function with a conditional that equals the custom post type then set the post meta using shortcode which includes the taxonomy termsthen apply a filter to the result to the genesis_post_meta function in your functions.php file.

You can choose to have the custom taxonomy on its own or a mixture with the regular categories and tags.

//Filter the Taxonomy Meta on a CPT
function themeprefix_genesis_post_meta_filter( $post_meta ) {
	if ( 'coaching_technique' == get_post_type() ) {//swap in CPT name
		$post_meta='[[post_terms taxonomy="difficulty-level" before="Difficulty Level: "]]';//swap in taxonomy and label name
		return $post_meta;
	}
	elseif ( 'post' == get_post_type() ) {
		return $post_meta;
    }
}
add_filter( 'genesis_post_meta','themeprefix_genesis_post_meta_filter', 11 );

 

tax-term

Only Custom Taxonomy is shown

In the example above the custom post type is ‘coaching technique‘, the taxonomy is ‘difficulty-level‘ and a before label of ‘Difficulty Level‘ is used.

 

If you wanted to also keep the categories and tag values also you would also add those in the post_terms values like so:

//Filter the Taxonomy Meta on a CPT
function themeprefix_genesis_post_meta_filter( $post_meta ) {
	if ( 'coaching_technique' == get_post_type() ) {//swap in CPT name
		$post_meta='[[post_categories before="Categorised Under: "]] [[post_tags before="Tagged: "]] [[post_terms taxonomy="difficulty-level" before="Difficulty Level: "]]';//swap in taxonomy and label name
		return $post_meta;
	}
	elseif ( 'post' == get_post_type() ) {
		return $post_meta;
	}
}
add_filter( 'genesis_post_meta','themeprefix_genesis_post_meta_filter', 11 );

The above would give all taxonomy terms, custom, categories and tags.

tax-cat-tag

Custom and Regular Taxonomy are shown

 

The code has an elseif option to return just the regular post meta; categories and tags for regular posts.
Thanks to Brad Potter for optimising the code.

Leave a Comment





%d bloggers like this: