Skip Navigation

[Resolved] How to set default value of custom search filter using shortcode?

This support ticket is created 3 years, 2 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 4 replies, has 2 voices.

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

Assisted by: Luo Yang.

Author
Posts
#2211355

Tell us what you are trying to do?
hidden link
I want to set the default value of country be "USA" in shortcode, I'm using elementor. And current shortcode I'm using is:

[wpv-form-view name="search-home-2" target_id="1763"]

#2211633

Hello,

The simplest way is passing URL parameter, for example:
hidden link

And you can setup custom JS codes to setup the default value, for example:

jQuery( document ).on( 'ready', function( event, data ) {
    jQuery('select[name="wpv-country"]').val('usa');
});
#2212021

Thank you Luo!

I added the custom JS to the page, but when page is loaded, it does preset the filter to be USA, but another filter on the right - "States & City" still shows cities in other country. Is there anyway to make it sync with the "Country" filter?

Thanks!

#2212093

I just installed a redirection plugin to pass the URL parameter when home page is loaded, but I feel it's not a good way to solve this problem. Would like to hear your suggestion. Thanks

#2212403

It needs other custom codes, for example:
1) Create a custom shortcode to setup the default URL parameter value, add below codes into your theme file "functions.php":

add_shortcode('set_default_url_param', function($atts){
    $atts = shortcode_atts( array(
        'param' => 'wpv-country',
        'value' => 'usa'
    ), $atts);
  
	if(!isset($_GET[$atts['param']])){
    	$_GET[$atts['param']] = $atts['value'];
    }
  	return;
});

2) Display above shortcode just above the view's shortcode, for example:

[set_default_url_param]
[wpv-form-view name="search-home-2" target_id="1763"]