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:
To not trigger the search the end of the string needs to be deleted starting from &asp_s=
, so it becomes:
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.
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:
This one only triggers with an empty phrase
In our case the console printed:
6) Copy/Paste the URL returned. You can repeat the steps if you need multiple setups.
Last updated