[Resolved] Display Custom Taxonomies on CPT Archive

Home Forums Support [Resolved] Display Custom Taxonomies on CPT Archive

Home Forums Support Display Custom Taxonomies on CPT Archive

Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
    Posts
  • #1541557
    Ryan

    Hey guys, I’m porting a theme from Genesis to GeneratePress. One small issue I’m having is styling my CPT Archive. I’m running the latest WordPress (5.3.3), Theme (3.0.2), and Plugin (1.12.2).

    I have two CPT taxonomies, Sticker Method & Sticker Category, that I display with Genesis using their built-in [post_terms] shortcode. You can see it in action on my site here and this is the code I use in my themes functions to pull it off.

    add_filter( 'genesis_post_meta', 'sticker_post_meta' );
    function sticker_post_meta( $post_meta ) {
    	if ( is_post_type_archive( 'hif_sticker' ) ) {
    	   $post_meta = '<i class="fad fa-desktop" aria-hidden="true"></i> [post_terms taxonomy="sticker_signup" before="Method: "] ·
           <i class="fas fa-tags fa-flip-horizontal" aria-hidden="true"></i> [post_terms taxonomy="sticker_category" before="Category: "] ·
           <i class="fas fa-exclamation-triangle" aria-hidden="true"></i> <a href="//www.heyitsfree.net/report-freebie/?report_link=I+believe+this+sticker+is+dead+'. get_permalink() .'" rel="nofollow">Report a dead sticker</a>!';
    	}
    	return $post_meta;
    }

    I’m struggling to figure out the GP equivalent to display these custom taxonomies, either via function or GP hooks.

    I tried the following code in a GP Hook, but it only output the term “Array” instead of the actual taxonomies, so I know I’m doing something wrong!

    <i class="fad fa-desktop" aria-hidden="true"></i> Method: <?php echo get_terms('sticker_signup'); ?> ·
    <i class="fas fa-tags fa-flip-horizontal" aria-hidden="true"></i> Category: <?php echo wp_get_post_terms('sticker_signup'); ?> · 
    <i class="fas fa-exclamation-triangle" aria-hidden="true"></i> <a href="//www.heyitsfree.net/report-freebie/?report_link=I+believe+this+sticker+is+dead+'. get_permalink() .'" rel="nofollow">Report a dead sticker</a>

    Thank you in advance for any help on this!

    #1542712
    Tom
    Lead Developer
    Lead Developer

    Hi there,

    If you want to use that method, you’d need to use a function like this: https://developer.wordpress.org/reference/functions/get_the_term_list/

    It will output the list of terms instead of an array.

    Alternatively, you can use our post meta system like this: https://generatepress.com/forums/topic/post-meta-for-custom-taxonomy-archives-and-category-archive/#post-1525707

    Hope it helps!

    #1543407
    Ryan

    Cheers, thanks Tom. Using your tip, I was able to get this working with get_the_term_list!

    #1544881
    Tom
    Lead Developer
    Lead Developer
Viewing 4 posts - 1 through 4 (of 4 total)
  • You must be logged in to reply to this topic.