Skip Navigation

[Resolved] drill down of fields in search criteria

This support ticket is created 2 years, 1 month 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
- 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 -
- 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 -

Supporter timezone: Asia/Karachi (GMT+05:00)

Author
Posts
#2317417
VENDOR LISTING FILTERING.jpg

Tell us what you are trying to do?
I have a vendor listing screen wherein the user must be able to drill down from state, to county, to city, to vendor category.
The search fields are in that order on screen.
The state field is a drop down showing only existing values.
The county field is a drop down showing only existing values.
The city field is a drop down showing only existing values.
The category field is a custom taxonomy called vendcat.
The category field is a dropdown.
Is there a way to cause the county field to show only counties for the selected state?
The county dropdown would have to be based on vendor records whose state value matches the value in the state field. This really is a no-brainer and should be possible.
Further, the city dropdown would have to be based on vendor records whose state and county values matches the values in the state and county fields. This drill-down is only logical. It isn't possible to give the user an intuitive and logical experience if counties from the entire country show up after selecting a single state. Likewise, it would be counter-intuitive and confusing to see cities from all over the country when you have selected a specific state and county.

Is there a similar example that we can see? hidden link

What is the link to your site? hidden link

#2318043

Waqar
Supporter

Languages: English (English )

Timezone: Asia/Karachi (GMT+05:00)

Hi,

Thank you for contacting us and I'd be happy to assist.

There are two possible approaches to achieve this:

1. Custom fields and custom taxonomies:

If you're using the custom fields and taxonomies to store the state, county, city data, it is not possible to link/join them in hierarchal levels.

However, there is a workaround and in the view's search settings, you can turn on the option "Show only filter options that would produce results". This updates the options in all the search form fields, whenever a selection is made in any one of the fields and only the options which can produce some results are kept. This means that as soon as a visitor will select a state, the search form will update and the city field will naturally only have the cities options which are related to the selected state and have some listings results associated with them.

Important note: The success of this approach is dependent on the correct data entry, i.e. correct state, county, city items are attached to all the listings.

2. Post Relationships:

If you'd like to truly link/join the state, county, city items in hierarchal levels, then instead of custom fields and taxonomies, you'll need to add them as separate custom post types.

For example, you'll have these custom post types:

- States
- Counties
- Cities
- Listings

Next, you'll join these custom post types through post-relationships:
- States -> Counties: One-to-many relationship, so that 1 state can have multiple counties.
- Counties -> Cities: One-to-many relationship, so that 1 county can have multiple cities.
- Cities -> Listings: One-to-many relationship, so that 1 city can have multiple listings.

In this structure, the lowest level item (Listings) is indirectly connected to the highest level item (States). For the sake of simplicity, I've only used 4 levels in this example, but you can introduce more levels in this structure as needed.

When you'll use the relationship filtering fields for these levels in the view's search ( ref: https://toolset.com/lesson-placement/lesson-placements-1622935-1621213/#how-to-search-by-post-relationships ), on the page load, only the "State" field will have the options, and fields for "Counties" and "Cities" will be disabled.

The visitor will first select the state, which will populate only the related counties in the county field. And when a county will be selected, only its related cities will become available in the city field.

I hope this helps and please let me know if you need any further assistance around this.

regards,
Waqar

This ticket is now closed. If you're a WPML client and need related help, please open a new support ticket.