• I’ve created a custom post type and everything is working beautifully…almost. I have managed to set tags and categories for my custom post type, they show up in the admin panel, they save and everything seems great. Just like a regular post.

    Where I’m now stuck is how to display these items in my loop or post. For example, with a regular blog post, you can put your meta data to show “posted in” or “filed under” (terminology up to the user) and then a sequence of category links. For example: Filed Under: Beauty / Fashion / Editorials

    While my categories and tags save with each new custom post type, I cannot for the life of me figure out how to publish it so that either in my list or in the actual post itself, I can have something like:
    ABC Logo (title of post)
    Thumbnail (featured image)
    Branding / Digital / Print (the categories and/or in which this falls under)

    Here is the code that sits in the functions.php file and as I said, it’s all working great. I just cannot find anything online (I’ve spent the entire day searching) for how to simply display the categories and tags within your custom post type (either in list or single view).

    register_taxonomy(
        'works',
        'portfolio',
        array(
            'label' => __('Portfolio Categories'),
            'singular_label' => __('Portfolio Category'),
            'hierarchical' => true,
            'query_var' => true,
            'rewrite' => true,
            'show_in_nav_menus' => true,
        )
    );
    
    // took out author and custom fields
    register_post_type('portfolio', array(
            'label' => __('Portfolio'),
            'singular_label' => __('Work'),
            'public' => true,
            'show_ui' => true,
            'capability_type' => 'post',
            'hierarchical' => false,
            'rewrite' => true,
            'query_var' => true,
            'show_in_nav_menus' => true,
            'menu_position' => 3,
            'taxonomies' => array('post_tag', 'category'),
            'supports' => array('title', 'editor', 'thumbnail', 'category'),
    register_post_type('portfolio', $args),
            '_builtin' => false, // It's a custom post type, not built in!
    ));

    Unfortunately my site is local while I build it out. This is the last remaining thing for me to figure out.

    I look forward to any and all responses!

    Many thanks,
    Matt

Viewing 9 replies - 1 through 9 (of 9 total)
  • Hi Matt,

    If you’re using the default category and tag taxonomies with your custom post type, you should be able to use standard display functions as well, e.g. the_tags or the_category.

    Thread Starter Matt

    (@fattyo)

    Hey Drew,

    Thanks for the response. The above solution works to display my blog categories and tags, but I don’t want them displayed in my portfolio section.

    I have categories that are specific to my custom post type. For example, in my blog area, I may have random categories but in my portfolio posts, I have categories like Print, Digital, Identity, etc. I have tried every which way for the past 3 days to display these categories in either the loop or single post and nothing works.

    Maybe it’s time to simply give up.

    Thanks again for your suggestion.

    I have categories that are specific to my custom post type.

    Are you using a custom hierarchical taxonomy or just using some categories with your CPT and some with other things? If you want true subdivision, you’ll be better off looking at register_taxonomy.

    Thread Starter Matt

    (@fattyo)

    This is my entire setup for my custom post type. The custom categories display in the WP admin panel as they should, but trying to get them to show on any template file is simply not working… I’ve read all docs and links that you’ve sent and then some.

    /*** Custom Posts ***/	
    
    add_action("init", "portfolio_init");
    
    function portfolio_init() {
    
    register_taxonomy(
        'works',
        'portfolio',
        array(
            'label' => __('Portfolio Categories'),
            'singular_label' => __('Portfolio Category'),
            'hierarchical' => true,
            'query_var' => true,
            'rewrite' => true,
            'show_in_nav_menus' => true,
        )
    );
    
    // took out author and custom fields
    register_post_type('portfolio', array(
            'label' => __('Portfolio'),
            'singular_label' => __('Work'),
            'public' => true,
            'show_ui' => true,
            'hierarchical' => false,
            'rewrite' => true,
            'query_var' => true,
            'show_in_nav_menus' => true,
            'menu_position' => 3,
            'supports' => array('title', 'editor', 'thumbnail'),
            '_builtin' => false, // It's a custom post type, not built in!
    ));
    
    }
    Thread Starter Matt

    (@fattyo)

    I realize that ‘taxanomies’ => array(‘post_tag’, ‘category’) is not in the register_taxanomy array, but it’s because when I add that in, the default categories that are setup for my blog automatically appear there.

    Sorry, I guess I misunderstood. Since you’re using a custom taxonomy afterall, take a look at get_the_term_list.

    To reproduce the look of what the_category() produces, you could use something like this:

    echo get_the_term_list( $post->ID, 'works', 'Works: ', ', ', '' );

    Thread Starter Matt

    (@fattyo)

    You, my friend, are a fine human being. Thank you so much.

    I’d tried that solution before, but I guess I was missing something. Now I just need to figure out how to remove the link status from each project. I’m creating a super, super simple portfolio and I just want it to state “Branding / Print / Digital” and no links to those categories/tags.

    Thanks again man!!!

    Thread Starter Matt

    (@fattyo)

    Got it all sorted.

    Thanks so much again. This seemingly simple task was killing me for days!

    Glad you figured it out. Seems like this topic is resolved.

Viewing 9 replies - 1 through 9 (of 9 total)
  • The topic ‘Categories in Custom Post Type Loop/List’ is closed to new replies.