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