Forums › Forums › Search & Filter Pro › List/Grid switcher AJAX
- This topic has 4 replies, 3 voices, and was last updated 6 years, 4 months ago by Ross.
-
Anonymous(Private) June 22, 2018 at 7:02 am #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.Ross Moderator(Private) June 27, 2018 at 8:35 pm #181437Hi 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
-
AuthorPosts