Skip Navigation

[Resolved] conditional search

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
- 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/Hong_Kong (GMT+08:00)

This topic contains 6 replies, has 3 voices.

Last updated by Luo Yang 3 years, 5 months ago.

Assisted by: Luo Yang.

Author
Posts
#1809575

Hi, I am building a directory listing website (car service).
To help users find car service shops in the nearby area, I want to create search filters that go like this:
States > Counties > Townships > Municipalities

The way I want it to setup is:
if State A is selected, only Counties in that state will be displayed in the County dropdown field
if County A is selected, only Townships in that county will be displayed in the Township dropdown field
etc

How should I go about doing it?
I've watched the video tutorials in https://toolset.com/course/wordpress-directory-and-classifieds-sites/
But cannot find what I am looking for.
Thanks in advance for taking the time to help me out on this...

#1810065

Nigel
Supporter

Languages: English (English ) Spanish (Español )

Timezone: Europe/London (GMT+00:00)

The way this is facilitated in Toolset is by creating custom post types for each level (e.g. for states, for counties, etc.) and then connecting each of these in one-to-many relationships (many counties belong to one state).

You then connect your listing posts to the municipality posts in another relationship, and when you add a listing to a municipality it is then implicitly connected to the other location types.

You can then insert a relationship filter into your search View and the ancestors can be included to give the workflow you describe, whereby users first select a state, then a county, then a township, then a municipality.

#1811977

Hi, I have successfully connected the said custom post types.
However, i am still lost as to how to create a relationship filter into the search View.
Can you point me to some video tutorials/documentations on how to do this?
I did my due diligence but couldn't find one that matches the setting I want to achieve.

#1812021

Hello,

Here is the document about "Creating a Custom Search in WordPress":
https://toolset.com/course-lesson/creating-a-custom-search/

In section "1. Creating the custom search form", there is a screenshot:
https://toolset.com/wp-content/uploads/2020/05/toolset-views-custom-search-3.png
There you can put the post type relationship into custom search form.

#1812329

Hi,

I actually watched the https://toolset.com/course-lesson/creating-a-custom-search/ video earlier but the video does not have the information I am looking for.
As mentioned in my earlier messages: I want to create search filters (dropdown) where user can select:
- states
- counties
- etc

to find the nearest car services shops.

What I cannot figure out after watching the video is how I can create those filters in such a way that when State A is selected, only counties in the that state get shown in the counties search filter?

I am using Post filters (Post relationship or repeatable field groups owner) for the Custom Search Filter (https://toolset.com/wp-content/uploads/2020/05/toolset-views-custom-search-3.png).

The problem is, I can only use it one. So, if I use it for State for instance, I can no longer use it for County, etc.

Where did I go wrong?

PS - I did create state, county, etc as custom post types as instructed. However, I did not create custom fields for each of the custom post type since I thought that the only information that's need for each post type is the type of post which is the name of each state, county, etc. Should I actually create custom fields even though it is for the name of the state, county, etc?

#1812393

Hi, I just wanted to let you know that I figured out where I went wrong.
Problem's solved now.
Thanks so much for your help and patience. I truly appreciate it.

#1813271

OK, feel free to create new ticket for other new questions.

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