Presetting search options via a custom URL
Setting search settings (checkboxes, dropdown etc..) via adding query arguments to current page URL
1) Navigate to the page with the search bar/settings you want to preset. In this example we are using the ajax search pro property demo example.
2) Preset the filters as you want them, for example:
3) Get your search ID. You can get the search shortcode ID on the plugin backend. In our case it is 16
4) Navigate back to the frontend with the search page. Now open your browser developer console via hitting F12. We are using Chrome. For other browsers CTRL + SHIFT + I may also work.
Make sure the console panel is highlighted:
5) Copy/Paste the following code to the console - but make sure to change the id variable to your search ID. The first part is to be used with the regular live search results, the second one works with Elementor Live loaded widgets.
1
// For regular live search use this:
2
var id=16;
3
ASP.api(id, 1, 'getStateURL');
4
5
// For Elementor live loader, use this:
6
ASP.api(id, 1, 'getStateURL')+'&asp_ls=';
Copied!
The console should return a URL, which when used will preset the filters to the desired state.
If you want to also use a search phrase and/or trigger the search, then use this code instead. Change the phrase variable as you need it (it can be an empty string as well to only trigger the search).
This one enters a phrase and triggers the search:
1
// For regular live search use this:
2
var id=16, phrase='my search phrase';
3
ASP.api(id, 1, 'getStateURL')+'&asp_s='+encodeURIComponent(phrase)+'&asp_id='+id;
4
5
// For Elementor live loader, use this:
6
var id=16, phrase='my search phrase';
7
ASP.api(id, 1, 'getStateURL')+'&asp_ls='+encodeURIComponent(phrase)+'&asp_s='+encodeURIComponent(phrase)+'&asp_id='+id;
Copied!
This one only triggers with an empty phrase
1
// For regular live search use this:
2
var id=16;
3
ASP.api(id, 1, 'getStateURL')+'&asp_s=&asp_id='+id;
4
5
// For Elementor live loader, use this:
6
var id=16;
7
ASP.api(id, 1, 'getStateURL')+'&asp_ls=&asp_s=&asp_id='+id;
Copied!
In our case the console printed:
1
https://ajaxsearchpro.com/property-search/?p_asid=16&p_asp_data=1&current_page_id=2401&woo_currency=USD&qtranslate_lang=0&filters_changed=1&filters_initial=0&termset%5Breale-state-location%5D%5B%5D=53&termset%5Breale-state-location%5D%5B%5D=54&termset%5Breale-state-location%5D%5B%5D=46&termset%5Breale-state-location%5D%5B%5D=51&termset%5Breale-state-location%5D%5B%5D=47&aspf%5Bre_property_type__2%5D=Villa&aspf%5Bre_bedrooms__3%5D%5Blower%5D=4.00&aspf%5Bre_bedrooms__3%5D%5Bupper%5D=6.00&aspf%5Bre_bathrooms__4%5D%5Blower%5D=2.00&aspf%5Bre_bathrooms__4%5D%5Bupper%5D=6.00&aspf%5Bre_price__5%5D%5Blower%5D=380000.00&aspf%5Bre_price__5%5D%5Bupper%5D=760000.00&asp_gen%5B%5D=title&asp_gen%5B%5D=content&asp_gen%5B%5D=excerpt&customset%5B%5D=asp_real_estate&asp_s=&asp_id=16
Copied!
6) Copy/Paste the URL returned. You can repeat the steps if you need multiple setups.
Last modified 2mo ago
Copy link