Presetting search options via a custom URL

Setting search settings (checkboxes, dropdown etc..) via adding query arguments to current page URL

Method #1 - via settings

If you open up the search settings, you can set to update the browser address bar on the Search Behaviour -> Live Search Triggers panel.

After updating navigate to the page with the search bar/settings you want to preset. Preset the filters as you want them.

The address bar on your browser will update with the current filter presets:

You can copy and use this URL, when visiting the filters are preset to this state and the search is triggered automatically.

Turning off the automatic search triggering when visiting the URL

You may only want to preset the search filters but not trigger the actual search when visiting. For that the end of the generated URL needs to be trimmed.

After copying, the end of the URL will look something like this:

....&current_page_id=578&asp_s=

To not trigger the search the end of the string needs to be deleted starting from &asp_s= , so it becomes:

....&current_page_id=578

Method #2 - Programmatically

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.

// For regular live search use this:
var id=16;
ASP.api(id, 1, 'getStateURL');

// For Elementor live loader, use this:
ASP.api(id, 1, 'getStateURL')+'&asp_ls=';

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:

// For regular live search use this:
var id=16, phrase='my search phrase'; 
ASP.api(id, 1, 'getStateURL')+'&asp_s='+encodeURIComponent(phrase)+'&asp_id='+id;

// For Elementor live loader, use this:
var id=16, phrase='my search phrase'; 
ASP.api(id, 1, 'getStateURL')+'&asp_ls='+encodeURIComponent(phrase)+'&asp_s='+encodeURIComponent(phrase)+'&asp_id='+id;

This one only triggers with an empty phrase

// For regular live search use this:
var id=16; 
ASP.api(id, 1, 'getStateURL')+'&asp_s=&asp_id='+id;

// For Elementor live loader, use this:
var id=16; 
ASP.api(id, 1, 'getStateURL')+'&asp_ls=&asp_s=&asp_id='+id;

In our case the console printed:

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

6) Copy/Paste the URL returned. You can repeat the steps if you need multiple setups.

Last updated

Copyright Ernest Marcinko