Skip Navigation

[Resolved] I can't figure out Custom field filters & Advanced search option

This support ticket is created 3 years, 7 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/Karachi (GMT+05:00)

This topic contains 2 replies, has 2 voices.

Last updated by hacerY 3 years, 7 months ago.

Assisted by: Waqar.

Author
Posts
#2057179

Tell us what you are trying to do?
I have created 3 dropdown select fields (Country, State, City) in my search view. If I select for example Canada, I want the State dropdown to show only states in Canada (in my case Ontario), and then the City dropdown should show cities that belong to the selected state (in my case Toronto).

Is there any documentation that you are following?
I found a ticket about how to do this, and I am trying to follow it. https://toolset.com/forums/topic/multiple-drop-downs-for-different-levels-of-taxonomy-in-custom-search-filter/

You say in this ticket:
"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."

I have these 3 custom select fields now, but I can't figure what to do next to make my idea work. I'm already using the Advanced Search option "Show only available options for each input" in the View to achieve this.

But on my site, now when I select Canada, the states dropdown shows Ontario but also Province of Vicenza (this is in Italy, not Canada). So this is not correct. Also when I choose Italy, it doesn't show any States (it should show Province of Vicenza). Another example, when I select United States, the states show New York and Ontario (this is Canada).

I can't figure out what to exactly to make this work correctly. I think I am missing a step, but I don't know what. Would you be able to guide me, please?

Is there a similar example that we can see?
This is a random site which search functionality I want to mimic: hidden link

What is the link to your site?
hidden link

#2057387

Hi,

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

For the approach suggested by Christian to work, it is important that the data entry part in those 3 custom fields is correct.

You'll need to make sure that In every post, the correct association data exists when it comes to the country, state, and city. If you're seeing the incorrect state or city when a country is selected, it is most likely because, in at least one of your posts, the incorrect country, state, the city has been entered.

To troubleshoot this, you can temporarily add single field blocks to show the added country, state, and city for each post in the view and you'll have a better overview, of why this is happening.

In case the data entered is correct and the issue still persists, you're welcome to share temporary admin login details, in reply to this message.

Note: Your next reply will be private and please make a complete backup copy, before sharing the access details.

Another alternative to using the 3 custom fields approach, would be using the 3 custom post types and then linking them together using the 1-to-many post-relationships.
( ref: https://toolset.com/course-lesson/what-are-post-relationships-and-how-they-work/ )

1. Custom Post Types
- Countries
- States
- Cities

2. Relationships
- One country can have many states
- One state can have many cities
- One city can have many posts that you're showing through the view.

With the data entered in this structure, you'll be able to show the 3 connected search fields (for countries, state & city), using the post-relationship filter in the search view.

regards,
Waqar

#2062601

Hello Waqar. Sorry for the delay in getting back to you.
My issue is resolved. I had to add some more listing/posts and then do some proper testing.
It works indeed. But I was just going to the next drop down field too fast. With other words: when you select a country in field one you need to wait 1-2 seconds for the system to filter the correct states for you in the states drop down field. The same goes for cities field. I think there are a lot of field options and this functionality takes time to render the proper field options.
Thank you for your help!