Skip Navigation

[Closed] Use categories as filter option

This support ticket is created 3 years, 5 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)

Author
Posts
#2074945

Tell us what you are trying to do?

Hello,
We are building a travel website with information about all continents, over 100 countries and several cities to each country.
They are all categorized with continents as the main category, country as a sub category and then city as a sub category to the country category.
Our goal is to have a filter function with different steps. So that if you choose for example "Europe", next filter dropdown will only show countries in Europe. Then the filter after that will only show cities in the chosen country.
The question: Is it possible to achieve this from the hierarchy of current categories and if so, how?

Thanks in advance!

#2075077

Hello, it sounds like you want to set up a multi-step taxonomy filter for a custom search View. If you plan to implement this in a single hierarchical taxonomy, unfortunately there is no built-in filter type that will achieve exactly what you're looking for in Views. It would require a significant amount of custom programming using JavaScript and PHP, and that level of customization falls outside the scope of support we offer here in the forums. An independent contractor may be able to help you set up something like this.

I can think of a couple of alternatives using built-in Toolset features that would accomplish something similar to, but not exactly like, what you have described. Let me explain both options for you to consider.
1. Use multiple flat taxonomies instead of one hierarchical taxonomy. In this scenario, instead of using one large hierarchical taxonomy, you will create 3 separate flat taxonomies - continent, country, and city. There are no direct relationships or connections between the terms in these taxonomies. Instead, the relationship between continent, country, and city are inferred by the system based on the assignment of these terms in your posts. You will create 3 separate taxonomy filters in a custom search View, one for each taxonomy. There is a View configuration option that will refresh the filter options as visitors make selections, so that the options available in the other filters are limited to those options that produce search results. In other words, the visitor will select one taxonomy term first...let's say they select "Europe" in the Continent filter. Then the options for the country and city filters update automatically. Any country or city terms that are not applied to posts that also have the "Europe" term will no longer be displayed as available options in the filters, or they will be displayed but inactive and unselectable. In this scenario, the order in which your visitors select these filters is not enforced in any way, so it is possible to select the country first, for example, or the city first.

In concept, alternative #1 is probably closer to what you had in mind because it uses taxonomy terms to assign and manage locations. The filtering experience is less alike than alternative #2, though.

2. Set up your Continents, Countries, and Cities as custom post types in hierarchical post relationships, instead of using taxonomies. In this scenario, you would not use taxonomies at all to represent these geographical constructs. Instead, you would have 3 custom post types, with relationships between these posts established by two One-to-Many (O2M) post relationships:
- Continent -> Country, where Continent is the parent or "One" side of the relationship and Country is the child or "Many" side of the relationship)
- Country -> City, where Country is the parent and City is the child.
When you have two or more O2M post relationships involving a chained set of post types like this, you can consider these relationships like generations, i.e. grandparent -> parent -> child. In this setup it is possible to create a custom search View with a filter for each "generation" of the relationship. The order in which the visitor can select from these filters is enforced, starting with the oldest ancestor. Subsequent generation filters are disabled until the User selects the oldest ancestor, then the next generation is activated, and so on.

In terms of search and filtering experience for the User, this option is the closest to what you've described. However, it requires a very different setup in wp-admin.

Let me know if you have follow-up questions about these alternatives, and I can give you more direct guidance.

The topic ‘[Closed] Use categories as filter option’ is closed to new replies.