Forums Forums Search & Filter Pro Let the user select the search results display mode

Viewing 6 posts - 1 through 6 (of 6 total)
  • Anonymous
    #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 (with get_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
    #30970

    Hi,

    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
    #31036

    Hey 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

    Anonymous
    #31073

    Hi Ross,

    Thank you for the answer.

    A custom filter to work with custom query_vars would be awesome ! Thank you for your work, I know you have a lot of things on your to do list already…

    Anonymous
    #182825

    Hello there,

    I see a new “sf_edit_query_args” filter is available since S&F v2.0. Does this mean I can pass my ?display= parameter in the URL with the plugin now?

    Thank you.

    Ross Moderator
    #183438

    Hi 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 and sf_ajax_results_url – if using ajax, then you’ll probably only need sf_ajax_results_url

    Saying that, if you can hold out a bit longer, we’ll have a nice filter for it in v3 🙂

    Thanks

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