Skip Navigation

[Resolved] Multiple drop downs for different levels of taxonomy in custom search filter

This support ticket is created 5 years, 9 months ago. There's a good chance that you are reading advice that it now obsolete.

This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.

Sun Mon Tue Wed Thu Fri Sat
8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 - -
13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 - -

Supporter timezone: America/New_York (GMT-04:00)

This topic contains 4 replies, has 2 voices.

Last updated by Ben 5 years, 9 months ago.

Assisted by: Christian Cox.

Author
Posts
#1192135

Ben
Required Dropdowns.png
Current Dropdowns.png

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!

#1192256

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.

#1200039

Ben

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.

#1200102

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/

#1201138

Ben

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.