- This topic has 3 replies, 2 voices, and was last updated 3 years, 4 months ago by Tom.
-
AuthorPosts
-
November 22, 2020 at 3:56 pm #1541557Ryan
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!
November 23, 2020 at 9:27 am #1542712TomLead DeveloperLead DeveloperHi 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!
November 23, 2020 at 8:11 pm #1543407RyanCheers, thanks Tom. Using your tip, I was able to get this working with get_the_term_list!
November 24, 2020 at 10:49 am #1544881TomLead DeveloperLead DeveloperGlad you got it working 🙂
-
AuthorPosts
- You must be logged in to reply to this topic.