Waqar came up with a brilliant solution so that I can display different parts of a taxonomy separately.
[https://toolset.com/forums/topic/display-different-parts-of-custom-taxonomy-separately/]
I was wondering if I can extend this somehow within a Custom Search View and find a way to have multiple drop downs in the filter for different levels of the taxonomy?
For example, see the screenshots to see the current example of how filtering by taxonomy is displayed now. Each child term is displayed under its parent as default.
I would like to be able to have three different drop downs, one for each level of the taxonomy. Then whichever parent term is chosen in the first, the second loads the child terms for that specific term, and then again for the third level of taxonomy term. See my mockup example in the screenshot 'Required Dropdowns".
Is there a way I can achieve this?
Thank you in advance, happy to clarify anything if it needs it!
Hi, in a Custom Search View, there isn't a built-in way to separate a single taxonomy filter hierarchically. You would have to create 3 different taxonomies - one for each level of hierarchy. Or, you could create 3 custom field filters, or create a post relationship filter for a grandparent / parent / child relationship. Beyond that, a custom code solution with advanced JavaScript is required to achieve this effect in a single taxonomy filter.
Thanks for the information Christian!
If I have 3 different taxonomies, then is there a way to link these? To make sure that cities would only stay with the correct countries for example?
How would your suggestion of 3 custom field filters or a post relationship filter work? I am trying to imagine how to implement this but I am struggling.
If I have 3 different taxonomies, then is there a way to link these? To make sure that cities would only stay with the correct countries for example?
Not directly, no. But you can use the Advanced Search option "Show only available options for each input" in the View to achieve something similar, indirectly. This setting updates the front-end filters each time a filter selection is made, removing filter options that would produce no results when combined with the current selections. One thing I should mention here is this option is most effective when there are just a few filters in the search. When a larger number of filters are available, this option can cause increased load times and delays between searches. More info about this setting:
https://toolset.com/documentation/user-guides/front-page-filters/advanced-settings-custom-search/
How would your suggestion of 3 custom field filters or a post relationship filter work?
For the custom field approach, you would create 3 custom select fields, one for each level of hierarchy. Each of the select fields contains all the available options for that level of hierarchy. Then when someone creates a post, they will select one option for each field. In a custom search View, there will be 3 filters. Each filter will show all the possible options for one level of hierarchy, and your site Visitors will make their filter selections. You can implement the Advanced Search option I described before here as well.
For the post relationship approach, you would have to create one custom post type for each level of hierarchy. Create one-to-many relationships between the post types to set the proper hierarchy. Then create posts for each Country, each City, each Neighborhood, etc. Link each post to its parent or children. Use the following guide to implement post ancestor filters:
https://toolset.com/documentation/post-relationships/how-to-display-related-posts-with-toolset/how-to-filter-posts-by-their-ancestors/
Thank you for all your help with this issue Christian.
I think a custom coded solution would be the best fit for what I want here so I will go down that route.