Show list of SUB-CATEGORIES x CUSTOM TAXONOMY 1 children x CUSTOM TAXONOMY 2 chi
-
I have a custom post type that uses the built in category taxonomy and two custom taxonomies. All three of the taxonomies are hierarchical, having children and grandchildren. For example:
Custom Post Type: Recipe
Categories: Everyday, Travel, Holiday
Sub-categories:
Everyday => none,
Travel => camping, road trip, destination
Holidays => easter, thanksgiving, xmasCustom Taxonomy #1 (Diet): Paleo, Vegan, Gluten-Free
Tax children #1:
Paleo => grain-free, grass-fed
Vegan => raw, fruitarian
Gluten-free => noneCustom Taxonomy #2 (Cuisine) : American, Asian, African
Tax children #2:
American => southern, pub
Asian => chinese, thai, indian
African => ethiopian*Some categories and taxonomies will naturally have many children (and grandchildren) while some will have none.
GOAL:
If a Recipe post is under any category and taxonomy that’s a parent, what we want is to display in the footer, a list of links that’re the result of child categories x child diets x child cuisines. For example:Let’s say that you’re on a recipe post with the following attributes…
Recipe post title: Quick Asian Vegan Meals For Holidays
category: Holidays
diet: Vegan
cuisine: AsianBecause this recipe post is filed under categories and taxonomies that have children, what we want is to show a list that’s 3 sub-categories x 2 sub-diets x 3 sub-cuisines, totaling 18 links, like this…
Quick Chinese Raw Vegan Meals For Easter
Quick Thai Raw Vegan Meals For Easter
Quick Indian Raw Vegan Meals For Easter
Quick Chinese Fruitarian Meals For Easter
Quick Thai Fruitarian Meals For Easter
Quick Indian Fruitarian Meals For EasterQuick Chinese Raw Vegan Meals For Thanksgiving
Quick Thai Raw Vegan Meals For Thanksgiving
Quick Indian Raw Vegan Meals For Thanksgiving
Quick Chinese Fruitarian Meals For Thanksgiving
Quick Thai Fruitarian Meals For Thanksgiving
Quick Indian Fruitarian Meals For ThanksgivingQuick Chinese Raw Vegan Meals For Xmas
Quick Thai Raw Vegan Meals For Xmas
Quick Indian Raw Vegan Meals For Xmas
Quick Chinese Fruitarian Meals For Xmas
Quick Thai Fruitarian Meals For Xmas
Quick Indian Fruitarian Meals For XmasWe want a list of links to show in the footer always, even if a recipe post is filed under any cat or tax that is not a parent.
So let’s say you have a different recipe post with the same attributes as the previous example, except now we swap Vegan (who’s a parent) with Gluten-free (who is not a parent). For example:
Recipe post title: Quick Asian Gluten-free Meals For Holidays
category: Holidays
diet: Gluten-free
cuisine: AsianNow we have 3 sub-categories x 0 sub-diets x 3 sub-cuisines, totaling 9 links. The resulting combo of links will now look like this…
Quick Chinese Gluten Free Meals For Easter
Quick Thai Gluten Free Meals For Easter
Quick Indian Gluten Free Meals For EasterQuick Chinese Gluten Free Meals For Thanksgiving
Quick Thai Gluten Free Meals For Thanksgiving
Quick Indian Gluten Free Meals For ThanksgivingQuick Chinese Gluten Free Meals For Xmas
Quick Thai Gluten Free Meals For Xmas
Quick Indian Gluten Free Meals For XmasWe have a foreach code snippet that will do this for us, BUT it will only work on recipe posts that have a parent cat or tax. If the recipe post doesn’t have either a parent cat or tax (like the Gluten-free example above), no list will show.
ALSO, the foreach code snippet shows ALL children and grandchildren of categories and taxonomies, making the list of links very very long. Ideally, we want the list to show ONLY the direct, immediate children, and not grandchildren.
I’m thinking we should maybe not use a foreach function and just query posts instead…hm. What do you think?
HUGE THANK YOU for those who’ve read up to this point and want to step up to the plate and help. Thank you so much in advance for all your help and patience! ??
- The topic ‘Show list of SUB-CATEGORIES x CUSTOM TAXONOMY 1 children x CUSTOM TAXONOMY 2 chi’ is closed to new replies.