How can I use GET parameters to preselect filters on search page?

Home Forums Product Support Forums Ajax Search Pro for WordPress Support How can I use GET parameters to preselect filters on search page?

This topic contains 2 replies, has 2 voices, and was last updated by Ernest Marcinko Ernest Marcinko 5 years, 3 months ago.

Viewing 3 posts - 1 through 3 (of 3 total)
  • Author
    Posts
  • #20605
    tavy87
    tavy87
    Participant

    I have a search page that uses frontend filters (theclaritylife.org/search).

    I would like to be able to visit this page various ways, from various landing pages. Depending on how I visit the search page I would like the frontend filters to be preselected. How can I achieve this? For example, if I visit theclaritylife.org/search?var1=value1 I would like the filter labeled var1 to preselect value1.

    If this isn’t possible, do you recommend any other method for using ONE search page and preselecting the values in some way? It doesn’t have to be via GET parameters, I just assumed that would be simplest.

    Thank you for your help!

    #20609
    Ernest Marcinko
    Ernest Marcinko
    Keymaster

    Hi,

    It might be actually possible, but it takes some time to get it right. The GET values are encoded into a single variable though, that needs to be copied. To make this work, please follow this guide:

    1. Temporarily, on the General Options -> Logic & Behavior panel, change the redirection options as following: https://i.imgur.com/FtD4ACy.png

    This will enable redirection to the /seach/ page with the filter states, whenever the magnifier button is clicked.

    2. On the search page, change some of the filters, and then hit the magnifier icon, that will reload to the same page, but the URL will contain some other encrypted information, and the filters are selected as before: https://i.imgur.com/rCfgGEd.png

    3. If you copy this URL and open in a new browser tab for testing, the search will open with the previously selected filters. Basically you can use this URL now to add to menus, or anywhere else, and it will redirect to the search page with the pre-selected filter states.

    4. Repeat steps 2-3 to generate as many URLs with the filter states as you need.

    5. Don’t forget to change back the options from step 1.

    That’s it, this should do the trick 🙂

    Best,
    Ernest Marcinko

    If you like my products, don't forget to rate them on codecanyon :)


    #20610
    Ernest Marcinko
    Ernest Marcinko
    Keymaster

    I just remembered, there is even a faster way using the browser developer tools:

    1. Open up the browser developer tools, by hitting F12 on your keyboard, while the search page is open, the reload the page. You should see this.

    2. Navigate to the Console panel, then copy/paste the following code there like so:

    ASP.api(1, 1, 'getStateURL')

    3. After hitting enter, it will print out a string. Copy that, it contains the URL to the current page with the filter states.

    4. Change the filters as you like, and just do step 2. each time, no need to reload the page, it will always print the URL with the changes.

    I hope this helps!

    Best,
    Ernest Marcinko

    If you like my products, don't forget to rate them on codecanyon :)


Viewing 3 posts - 1 through 3 (of 3 total)

You must be logged in to reply to this topic.