Ajax Search Pro Knowledge Base
Buy Ajax Search Pro!DocumentationGet SupportDevelopment
  • Knowledge Base
  • Safe Coding Guideline
  • Hooks
    • Filters
      • Query & Output
        • asp_query_args
        • asp_query_{type}
        • asp_cached_content
        • asp_pre_get_front_filters
        • asp_before_ajax_output
        • asp_shortcode_output
        • asp_print_search_query
      • Keyword Suggestions
      • Search Results
        • asp_suggested_phrases
        • asp_results
        • asp_cpt_results
        • asp_buddyp_results
        • asp_attachment_results
        • asp_comment_results
        • asp_blog_results
        • asp_terms_results
        • asp_peepso_group_results
        • asp_peepso_activities_results
        • asp_only_keyword_results
        • asp_only_non_keyword_results
        • asp_result_groups
      • CSS & JS
        • asp_load_js
        • asp_load_css
        • asp_load_css_js
      • Template & Output
        • asp_icl_t
      • Index Table Related
        • asp_index_on_save_stop
        • asp_indexing_keywords
        • asp_indexing_string_pre_process
        • asp_indexing_string_post_process
        • asp_post_content_before_tokenize_clear
        • asp_post_content_before_tokenize
        • asp_post_excerpt_before_tokenize
        • asp_post_title_before_tokenize
        • asp_file_contents_before_tokenize
        • asp_post_permalink_before_tokenize
        • asp_index_terms
        • asp_post_custom_field_before_tokenize
        • asp_index_cf_contents_before_tokenize
        • asp_index_before_shortcode_execution
        • asp_index_after_shortcode_execution
    • Templating
      • Filter layouts Templating
      • Result Templating
    • Constants
  • Frontend Filters
    • Taxonomy Filters
      • Restricting results to the same category as the current post object
      • How to automatically check/select filter values based on the archive page?
    • Frontend filters API
  • Tips & Miscellaneous
    • Divi
      • Divi Blogs Live Search and Filter
    • Jet Engine
      • Jet Engine Listing Grid Live Search and Filter
      • Searching Jet Engine Custom Meta Storage fields
    • Tutorials
      • PDF results thumbnails
      • Demo setup: Staff search and Filter
      • Demo Setup: WooCommerce Search
      • Demo setup: WooCommerce Shop Search and Filter
      • Demo Setup: Events Search – Events Manager
      • Demo Setup: Events Search – The Events Calendar
      • Compact ‘pop-out’ search bar placement on specific pages only
      • Index Table – Indexing ACF repeater field titles and contents
      • Change Suggested Phrases conditionally
      • How to add shortcode to the results content?
      • How to add variables to the “redirect to url” or the “show more url”?
      • Indexing Shortcodes within custom field contents
    • Post Types
      • Index Table - Indexing child post contents to parent
      • Limit results to specific post IDs only
      • Filter posts (or CPT) which user can’t access
      • Restricting results by user Groups using the Groups plugin by itthinx
      • Limiting results to specific posts by parent ID
      • Limit results to current page children
      • Excluding posts or CPT by parent ID(s)
      • Searching posts, pages (or any CPT) by specified keywords only, nothing else
      • Showing the post type name in result title or content
      • Searching within given categories/taxonomy terms only
      • Search only in the same category as the current post or page (single page)
      • Search only within the current category (or any taxonomy) archive
      • Filtering pages by page template
    • Taxonomy Terms
      • Displaying taxonomy name in taxonomy term results
      • Limiting taxonomy term results to specific term IDs only
    • WooCommerce
      • Displaying On Sale products only in WooCommerce
      • Ordering product by stock status
      • Making a product in-stock & out of stock filter
      • Add to cart button for Vertical and Horizontal results
      • Get formatted price in result title or in content
      • Showing products in-stock only
      • Showing in-stock and backorder products only
      • Excluding hidden catalog products
      • Showing featured products first
      • How to search products & product SKU?
      • How to search Products by variation SKUs?
      • Search product attributes
      • How to search users by city, state, zip code… ?
    • Compatibility
      • WPML Compatibility issues and fixes
    • Files & Media
      • Searching Image EXIF metadata
    • Other
      • Restrict results from the current author archive page
      • Presetting search options via a custom URL
      • Matomo analytics tracking integration
      • Replace search keywords (whole words)
      • Replace or remove characters from search phrase
      • Adding spaces in search phrase between alphabetics and numbers
      • How to change the results URL to something else?
      • Numbering the results
      • How to use the search without the live ajax feature, as a regular search?
      • Empty search input field on the search results page
      • Singular and Plural keywords index
  • Other
    • SearchQuery
    • REST API
    • Building a custom REST API
    • Javascript API
    • Javascript Hooks
      • asp_redirect_url
      • asp_search_data
      • asp_live_load_html
      • asp_search_html
      • asp_compact_width
    • Theme Functions
Powered by GitBook
On this page
  • Method #1 - via settings
  • Turning off the automatic search triggering when visiting the URL
  • Method #2 - Programmatically
  1. Tips & Miscellaneous
  2. Other

Presetting search options via a custom URL

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

PreviousRestrict results from the current author archive pageNextMatomo analytics tracking integration

Last updated 1 year ago

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 .

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:

// 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.

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 widgets.

Elementor Live loaded
property demo example