How do I show a Custom Taxonomy?

Community Forums Forums Design Tips and Tricks How do I show a Custom Taxonomy?

This topic is: not resolved

This topic contains 4 replies, has 3 voices, and was last updated by  ischbins 2 years ago.

Viewing 5 posts - 1 through 5 (of 5 total)
  • Author
  • #62085



    I recently created a custom post-type called ‘portfolio’ following the tutorial that Brian Gardner made on his site: I registered a new Custom Taxonomy called ‘Location’ and am looking to have the ‘Location’ present itself in the ‘Portfolio’ metadata.

    My current code in the functions.php file is as follows:

    function add_custom_taxonomies() {
    	// Add new "Locations" taxonomy to Posts
    	register_taxonomy('location', 'portfolio', array(
    		// Hierarchical taxonomy (like categories)
    		'hierarchical' => true,
    		// This array of options controls the labels displayed in the WordPress Admin UI
    		'labels' => array(
    			'name' => _x( 'Locations', 'taxonomy general name' ),
    			'singular_name' => _x( 'Location', 'taxonomy singular name' ),
    			'search_items' =>  __( 'Search Locations' ),
    			'all_items' => __( 'All Locations' ),
    			'parent_item' => __( 'Parent Location' ),
    			'parent_item_colon' => __( 'Parent Location:' ),
    			'edit_item' => __( 'Edit Location' ),
    			'update_item' => __( 'Update Location' ),
    			'add_new_item' => __( 'Add New Location' ),
    			'new_item_name' => __( 'New Location Name' ),
    			'menu_name' => __( 'Locations' ),
    		// Control the slugs used for this taxonomy
    		'rewrite' => array(
    			'slug' => 'locations', // This controls the base slug that will display before each term
    			'with_front' => false, // Don't display the category base before "/locations/"
    			'hierarchical' => true // This will allow URL's like "/locations/boston/cambridge/"
    add_action( 'init', 'add_custom_taxonomies', 0 ); 
    /* ----------------------- PORTFOLIO CODE --------------------------- */
    /** Creates portfolio featured image for archive grid */
    add_image_size( 'portfolio', 330, 230, TRUE );
    /** Create portfolio custom post type */
    add_action( 'init', 'portfolio_post_type' );
    function portfolio_post_type() {
        register_post_type( 'portfolio',
                'labels' => array(
                    'name' => __( 'Portfolio' ),
                    'singular_name' => __( 'Portfolio' ),
                'exclude_from_search' => true,
                'has_archive' => true,
                'hierarchical' => true,
                'taxonomies'   => array( 'location' ),
                'menu_icon' => get_stylesheet_directory_uri() . '/images/icons/portfolio.png',
                'public' => true,
                'rewrite' => array( 'slug' => 'portfolio' ),
                'supports' => array( 'title', 'editor', 'author', 'thumbnail', 'excerpt', 'trackbacks', 'custom-fields', 'comments', 'revisions', 'page-attributes', 'genesis-seo', 'genesis-cpt-archives-settings' ),
    /** Change the number of portfolio items to be displayed (props Bill Erickson) */
    add_action( 'pre_get_posts', 'minimum_portfolio_items' );
    function minimum_portfolio_items( $query ) {
        if( $query->is_main_query() && !is_admin() && is_post_type_archive( 'portfolio' ) ) {
            $query->set( 'posts_per_page', '12' );

    Any suggestions as to how to make the Taxonomy stuff list where the post metadata would?

    Thanks in advance!



    Ok, I think I’ve done something like this and therefore I’d like to share it with you.

    1. Genesis already has a built in shortcode. There’s a less-known shortcode to output any custom taxonomies, [post_terms].


    So you might use something like this [post_terms taxonomy="location"]

    2. You can put the shortcode in post info or post meta section (referred as Entry Meta in HTML5-enabled theme). Here are some links to customize it

    3. Since we only want to output the custom tax in Portfolio CPT we can combine the code above with conditional tag and filter.

    Take a look at this link, see the second block of code

    Hope that helps

    • This reply was modified 2 years, 2 months ago by  wpspeak.
    • This reply was modified 2 years, 2 months ago by  wpspeak.


    Hey wpspeak, thanks for responding!

    This is definitely very helpful information (and great links), but unfortunately it looks as though I may have somehow registered the Taxonomy incorrectly or be looking at the wrong label for calling upon the Taxonomy for the shortcode. I’m going to take another looksie and see what I’ve done incorrectly.

    (I’ve tried to add the taxonomy in every way possible presented by those links, but I always get a blank space where it should print, so obviously I’ve done something wrong!)



    After taking a further look, it appears that the ‘location’ taxonomy isn’t fully connecting (despite being able to add custom locations to Portfolio posts) or I am writing the PHP code for filtering in the taxonomy incorrectly.

    However, I think the latter might not be likely, as I’ve tried simply throwing the [post_terms] and [post_terms taxonomy="location"] shortcodes into the appropriate hook in Genesis Simple Hooks with nothing to show for it.

    Any ideas on what I might have done wrong?



    Hi all,
    just a comment from my side and a further question to this topic.

    @jondonley: I am using the Genesis “Simple Hooks” plugin and edited in the genesis_after_post_content Hook the following shortcode:

    [post_terms sep=", " before="Ausstattung: ", taxonomy="ausstattung"]

    So far it works fine. All my taxonomies from “ausstattung” are shown under my post.

    Now coming to my question: I don’t know why, but the command before=”Ausstattung: “ doesn’t work!?!?
    Furthermore it is shown the German word “Kategorie” before the list of taxanomies!
    I have no idea where this “Kategorie” comes from!
    Does anybody know how to get rid of this “Kategorie” and how to display before=”Ausstattung: “ ?

    Would be great, if anybody could give me a hint.
    Thanks in advance & best regards!

Viewing 5 posts - 1 through 5 (of 5 total)

You must be logged in to reply to this topic.