I have the following custom fields: wpcf-country, wpcf-state-usa, wpcf-state-canada,
The country filter has USA and Canada as its options (dropdown) and I'm able to filter by them right now.
I need the states filter to appear when a user selects a country from the country filter, i.e. if country is USA, state-usa dropdown filter has to appear and if country is Canada, state-canada dropdown filter has to appear. This I am unable to do. What would be the code to create a condition based on the first filter?
This comes to my mind - might be incorrect:
[wpv-filter-start hide="false"]
[wpv-filter-controls]
[wpml-string context="wpv-views"]Filter by Country:[/wpml-string]
[wpv-control field="country" url_param="country" type="select" auto_fill="wpcf-country" auto_fill_sort="asc"]
[wpv-filter-reset reset_label="Clear"]
[/wpv-filter-controls]
<br/><br/>
[wpv-filter-controls]
[wpv-if evaluate="'[control field='country'][/control]' == 'United States'"]
[wpml-string context="wpv-views"]Filter by State:[/wpml-string]
[wpv-control field="state-usa" url_param="state-usa" type="select" auto_fill="wpcf-state-usa" auto_fill_sort="asc"]
[wpv-filter-reset reset_label="Clear"]
[/wpv-if]
Thanks.
To enjoy all new features that Views can provide, you should get the latest version of it, 1.6.4.
Then I would recommend you to read the blog post below:
https://toolset.com/2014/06/learn-build-flexible-parametric-searches/
There is a section called "Input dependency in parametric searches" that explains this feature.
You could also download some reference site of us, "Real State" is one of them that uses this feature. You can do that using our Framework Installer. Do you know that? Using this plugin you can download a lot of nice reference sites to use or to learn more about our products.
All customers are invited to download it: https://toolset.com/my-account/downloads/
Thanks, I'll check this out.
Just to confirm, I can't get it done the way I was trying - using the if condition to compare the selected value with a string and display another drop down accordingly?
Just saw that the valid shortcodes inside [wpv-if] does not include the control field.
I'm on 1.6.1 - there's no input dependency in this version? (https://toolset.com/2014/05/views-1-6-1-parametric-search-bootstrap-layout/)
Any way to do it without upgrading to 1.6.4? Will check out if I can get the new version of it - I'll have to contact the owner of the plugin to do that.
The documentation is lengthy. I just need to display the appropriate states drop down filter as per the chosen country. Can you help me out if there's a way using the if shortcode?
Can I use JavaScript along with the shortcodes to get what I want?
I'm going to install 1.6.1 version and see if it can be done. I will let you know as soon as I have tested it.
My apologies the long delay. I've just installed the 1.6.1 version and also the Bootstrap Real Estate reference site, using the Framework Installer plugin.
The dependency works fine in this version. But you can not do that like you are trying to do. There is no way to set up the dependency functionality between Types custom fields. That's because there is no way to create a relationship between custom fields.
For this you must create a custom post type to State and another one to Country, then you should make Post and Country children of State. Then make property children of Country.
Now you have to add the right filter (relationship one). The elements of the search form should be like this:
[wpv-control-item type="select" ancestor_type="states" default_label=""]
[wpv-control-item type="select" ancestor_type="countries" default_label=""]
Thanks!
The issue is I'm working with Gravity Forms, and their entries are going inside custom posts and being displayed by views. Gravity Forms is not allowing me to enter into multiple posts from one form. There's the "post title" field which can only be entered once inside a form, which means entries go inside one custom post type from a form.
I did try without the post title and just the custom fields, but they weren't getting inside those custom post types - States and Countries. Without multiple custom post types I won't be able to build relationships and make the filters.
Any suggestions on what I should do?
I see what you mean. But unfortunately the only way to work with conditional dropdown in Views is through custom post types. I can't imagine a workaround for this, sorry.
You will need some custom code to achieve that, I hope you understand that this is out of the scope of our support.
At this point I would suggest you consider contacting one of our certified partners from this link: https://toolset.com/consultant/
You will get the custom assistance you need to get on with your project.
I understand. I'll see what I can do.
Thanks for your help, Adriano.
You are welcome.
Is there anything else I can help you with?
Just one more thing.
I do have access to the plugin owner's account now. Do you think upgrading to 1.6.4 will help me with what I'm trying to achieve?
There are some fixes and new features, but nothing related to your need. The way we work with conditional dropdown (dependency) hasn't been changed.