Community Forums › Forums › Archived Forums › General Discussion › Show Specific Taxonomy Types in Genesis Entry Footer / Post Meta / Post Terms
Tagged: get terms, is_tax, post terms, taxonomy type
- This topic has 6 replies, 2 voices, and was last updated 8 years, 1 month ago by
SeoGreenPea.
-
AuthorPosts
-
March 20, 2017 at 4:58 am #203435
SeoGreenPea
MemberI have a custom post type "Books" with a taxonomy type "book-type".
Within my "book-type" taxonomy, I have multiple child taxonomy types.
Here's an example of how I have things structured...
Books - (cpt)
Fictional Books (taxonomy)
-Scary (child taxonomy type of "Fictional Books")
--Reading Level 1 (child taxonomy type of "Scary")
--Reading Level 2 (child taxonomy type of "Scary")
--Reading Level 3 (child taxonomy type of "Scary")
--Ages 5-10 (child taxonomy type of "Scary")
--Ages 10-15 (child taxonomy type of "Scary")Let's assume I created a new "Books" CPT...
Title: 5 Scary Creepy Crawling Insects
Let's assume I have attached the following taxonomy types to it...
Scary
Reading Level 2
Ages 5-10I only want the "Scary" (child taxonomy type of "Fictional Books") & the "Reading Level 2" (child taxonomy type of "Scary"), while EXCLUDING "Ages 5-10" from showing in the post meta / post terms on the front end. I'm keeping the "Ages 5-10" attached for the book to show up within my "Ages 5-10" archives.
Here's the code I'm currently using.
//* Display Entry Footer Category & Taxonomy Post Meta add_filter( 'genesis_post_meta', 'custom_post_meta_filter' ); function custom_post_meta_filter($post_meta) { if ('book' == get_post_type() || is_tax( 'book-type' ) ) { $post_meta = '[post_terms taxonomy="book-type" before="Type Of Book: "]'; return $post_meta; } elseif ( is_singular ) { $post_meta = '[post_categories before="Filed Under: "]'; return $post_meta; } }
This works as it should by displaying all types on the front end...
Type Of Book: Scary, Reading Level 2, Ages 5-10But I only want it to show...
Type Of Book: Scary, Reading Level 2Is there a way to only include the taxonomy types by "id"?
Instead of...
[post_terms taxonomy="book-type" before="Type Of Book: "]
Maybe something like?...
[post_terms tax_id=(array(5,12,9) before="Type Of Book: "]Anyone out there smart enough or have any ideas on how to go about this using Genesis?
March 20, 2017 at 6:57 am #203441Brad Dalton
ParticipantMarch 20, 2017 at 7:21 am #203446SeoGreenPea
MemberI guess I'm not quite following you, but I appreciate your time in suggesting.
Still looking for a solution.
Thanks.
March 20, 2017 at 7:31 am #203449Brad Dalton
ParticipantYour shortcode uses get_the_term_list which doesn't enable you to exclude terms.
So you may need to filter it using genesis_post_terms_shortcode and use a more flexible function like get_terms which enables you to include or exclude terms.
March 20, 2017 at 7:57 am #203452SeoGreenPea
MemberThank you, I'll have to look into "filter it using genesis_post_terms_shortcode" which I'm not familiar with.
I thought I'd offer up another solution I'm considering trying out.
Each of my taxonomies have a custom field value that I'm using to output throughout the site elsewhere and for markup purposes.
I thought I might skip the entire...
if ('book' == get_post_type() || is_tax( 'book-type' ) ) {
$post_meta = '[post_terms taxonomy="book-type" before="Type Of Book: "]';
return $post_meta;
}and just use a function similar to...
add_action('genesis_entry_footer', 'custom_post_meta_filter'); function custom_post_meta_filter() { if ('book' == get_post_type() || is_tax( 'book-type' ) ) && genesis_get_custom_field('book_tax_type_name_scary') ) && genesis_get_custom_field('book_tax_type_name_reading_level_one') ) echo '<p class="entry-meta">Type Of Book: '. genesis_get_custom_field('book_tax_type_name_scary') .', '. genesis_get_custom_field('book_tax_type_name_reading_level_one') .'</p>'; }
But then because I'm using approximately 100 different taxonomy types that all have approximately 10-15 child taxonomy types, I'd end up writing a ton of functions. Assuming my above example would even work. The additional problem with the above code is that I wouldn't have the permalink attached to the custom field, which is also another obstacle.
I'm sure I can learn how to include the permalink, but I'll have to see if the code above even accomplishes what I'm after.
Using the genesis_post_terms_shortcode sure sounds easier and more efficient though.
Thanks for your input!
March 20, 2017 at 8:09 am #203455Brad Dalton
Participanthahaha, Thats exactly what i did here as it was so much easier to work with.
Didn't test your code but it looks like a easy solution.
March 20, 2017 at 9:15 am #203471SeoGreenPea
MemberI appreciate you providing your input, referenced options and examples.
I'll still need to probably figure out how to create my own custom genesis post terms shortcode using the get_terms method so I can select a specific taxonomy and exclude the others that are attached to my custom post type. Because I have tons of taxonomies and child taxonomies, my code above might not be efficient, even if I did figure out how to attach a permalink to a custom field.
Thank you.
I'm still looking for a solution that will work for my issue.
-
AuthorPosts
- The forum ‘General Discussion’ is closed to new topics and replies.