Forums Forums Search & Filter Pro List/Grid switcher AJAX

Viewing 5 posts - 1 through 5 (of 5 total)
  • Anonymous
    #181022

    Hi guys,

    A client has requested a view switcher on a search results page and I have nearly gotten this working but have run into a snag. The view switcher is intended to allow the user to switch between grid and list views of a results archive.

    I searched the plugin for a potential solution but was not able to find anything that is suitable. I built something custom using url queries and javascript that works but my problem now is that the query string I appended to the url is being stripped by sf pro whenever an ajax request is made.

    Is it possible to include a custom query string in the ajax request? or at least get it to read the contents of the url before submitting the request. I have built some functionality that reads from the query string in the archive.php template and will use the query string to print the appropriate grid or list view markup. This will work with ajax as long as the query string is passed with the rest of sf query strings.

    Any help is appreciated.

    Cheers,
    Josh.

    Trevor
    #181036

    Hi

    We do have events that you can watch for when Ajax is triggered. See the FAQ page for basic details. Maybe you could use these?

    https://searchandfilter.com/documentation/faq/

    Anonymous
    #181103

    Hi Trevor,

    I don’t need to detect the event, I need to modify the ajax request params. Do you know how I can achieve this?

    Cheers,
    Josh.

    Trevor
    #181110
    This reply has been marked as private.
    Ross Moderator
    #181437

    Hi Liam

    You can do it by modifying the results URL and adding your param there:

    function add_query_arg_to_results_url( $url,  $sfid) {
      // Process URL here
      return add_query_arg('view', 'grid', $url);
    }
    add_filter( 'sf_results_url', 'add_query_arg_to_results_url', 10, 2 );

    This is actually not the intended use of this filter, and there will likely be better way to do this in v3 (when it comes out)

    Thanks

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