Site logo

Archived topic

CPT - show custom taxonomies

5 replies · Started by Alexander on June 3, 2020

Viewing posts 1–6 of 6

Hello,

first - I searched, I really did. I figured this MUST have been asked before, but I just couldn't find an answer.

I finally took the plunge and added a custom post type "plant" to my site. I've gotten pretty far already and it's all working quite well as far as I can see (masonry, columns, etc.). I also have created custom taxonomies for this CPT (plant_category and plant_tag) and what I can't figure out is how to get these custom taxonomies shown for each post in the archives.

I found https://docs.generatepress.com/article/generate-footer-meta-post-types/ but that shows the WP core "category" and "tags" - and not the ones that I assigned/attached/linked/chained to my custom post type.

Any help would be appreciated.

Thanks!
Alexander.

Hi there,

you can use the generate_category_list_output filter

https://docs.generatepress.com/article/generate_category_list_output/

and for tags the generate_tag_list_output filter

https://docs.generatepress.com/article/generate_tag_list_output/

Example use for adding your custom taxonomy to the terms lists:

add_filter( 'generate_category_list_output', function( $output ) {
    $terms = get_the_term_list( get_the_ID(), 'your_custom_taxonomy', '', ', ' );

    return $output . '<span class="terms"> | ' . $terms . '</span>';
} );

Hello David,

I fear it's not quite clear to me what to do now, or I'm missing some kind of connection here. It would seem to me that the snippet https://docs.generatepress.com/article/generate-footer-meta-post-types/ is for both the single item view and the archives.

When I adjust it to my "plant" CPT, it does show the navigation in the single item view (ie. https://www.alex-kunz.com/plant/acmispon-americanus-spanish-clover/) and the comment count in the archives (ie. https://www.alex-kunz.com/plant/) - but it doesn't show the plant CPT's category & tag, in either the archives or the single item view.

How do I tell "generate_footer_meta_post_types", with the filters you mentioned, to use the "plant" CPT's category & tags, instead of the normal post category & tags?

Thank you for your help!
Alexander.

Adjusted for my needs and works. Awesome!

Considering that this is only ~3 weeks old and I couldn't find it, maybe a more generalized version of this would be worthy adding the the docs/help articles? :) CPTs with custom taxonomies are fairly common, aren't they? (thinking Jetpack Portfolio, Jetpack Testimonials, etc. etc.)

Thank you, Tom!

I agree - we'll get it added :)

Thanks!

This archived topic is closed to new replies.