Hierarchical Taxonomies confusion
-
Hello,
I am getting rather confused trying to figure out the understanding behind a function of hierarchical taxonomies in WordPress.
I am using WooCommerce, which has a taxonomy called
product_cat
. This goes by the readable name ofCategory
.I have a number of these categories set up in a hierarchy like below:
Vans
– For Sale
– For HireI’ve discovered that clicking “For Hire” will not automatically add the parent category of “Vans”. I wish to know the logic and thinking behind this decision and why a hierarchical taxonomy works like this as it doesn’t appear to make any sense to me? Maybe there is a sound reason behind it but I just want to find out what that is?
For the project I am working on, I have two features that require the parent categories to added when a child one is selected.
My main reason for wanting this is to keep it simple for my client.
The two features relying on this are:
1. I have a list of WooCommerce products that get output as a grid on my page. I wish to display an icon next to the product name of each one, but the icon is dependent on a class of “product_cat-vans” which only appears to be added, if the “Vans” category is actually selected rather than just a child category.
2. I have a custom field group (from the Advanced Custom Fields plugin) defined that will show up for the WooCommerce Product Custom Post Type when a taxonomy term of “Vans” is selected. Obviously, with the way things currently work, if my client clicks “For Hire” or “For Sale” then the custom field group doesn’t show up and therefore does not present him with the options and fields he needs for that product type.
I’ve done a lot of searching around online and seen many articles with names like “The Ultimate Guide to WordPress Taxonomies” but not a single one of them mentions that selecting a child term does not select the parent terms in a hierarchical setup? What is the point of it being hierarchical if this does not happen? I can’t seem to get my head around it!
I’ve also seen this question here: https://www.ads-software.com/support/topic/parent-category-doesnt-check-when-selecting-a-child-taxonomy/
This is sort of my question, but the poster also states that it works correctly for standard Categories for Posts, etc but it doesn’t in my testing?
The reply to that question gave a suggestion of using a bit of javascript to dynamically select any parents when a child is selected and, yes that should sort things out but it doesn’t help my understanding of why it doesn’t work like this in the first place.
I’d love to hear back from someone with some knowledge in this area and who can point me in the right direction.
Many thanks,
Neil
- The topic ‘Hierarchical Taxonomies confusion’ is closed to new replies.