Forums › Forums › Search & Filter Pro › Let the user select the search results display mode
Tagged: ajax, display mode, url parameter
- This topic has 5 replies, 2 voices, and was last updated 6 years, 5 months ago by Ross.
-
Anonymous(Private) November 29, 2015 at 12:37 pm #30967
Hi,
My website have multiple ways of displaying content (ex: Grid, List, Table / Compact, Expanded).
I am looking to add a button to let the user select how to display the search results. Basically, this button add a new parameter in the URL (something like
display=
) and reload the search results in AJAX. In the template files I load a different view (withget_template_part
) based on the display parameter in the URL.My problem is to getting it working with the “Search & Filter” plugin. The display parameter in the URL disappear when the user choose a new filter. How could I ensure that the parameter is persistent with “Search & Filter” ?
Thank you very much
Anonymous(Private) November 29, 2015 at 4:09 pm #30970Hi,
To explain further the problem, this is the function that lets you add an URL parameter recognized by WordPress with
query_vars
:function add_new_parameter_queryvars( $qvars ) { $qvars[] = 'display'; return $qvars; } add_filter('query_vars', 'add_new_parameter_queryvars' );
This is the code in the template file to do things with the new parameter :
global $wp_query; if (isset($wp_query->query_vars['display']) && $wp_query->query_vars['display'] == "grid") { // Do something. }
I am still trying to make the new parameter persistant with “Search & Filter”.
Ross Moderator(Private) November 30, 2015 at 4:53 pm #31036Hey there
This is actually not supported yet in S&F.
Essentially the issue is that the search URL actually gets created via JavaScript (to save on http requests) which means the standard add_query_vars doesn’t work.
I have been planning on allowing this sometime via a custom filter – let me have a think about implementation and see if its something I can squeeze into the next update.
Thanks
Ross Moderator(Private) July 25, 2018 at 1:04 pm #183438Hi again 🙂
We never added it properly as a feature in our v2 branch, instead opting to adding it to v3 (coming out in the next few months) – however, another one of our filters should do the trick:
https://searchandfilter.com/documentation/action-filter-reference/#modify-urls
What you will want to use is the
sf_results_url
andsf_ajax_results_url
– if using ajax, then you’ll probably only needsf_ajax_results_url
Saying that, if you can hold out a bit longer, we’ll have a nice filter for it in v3 🙂
Thanks
-
AuthorPosts