Support Forums

The forums are closed and will be removed when we launch our new site.

Looking for support? You can access the support system via your account.

Forums Forums Search & Filter Pro Pass Search Query to another instance of S&F

Viewing 8 posts - 1 through 8 (of 8 total)
  • Danny Albeck
    #256219

    Hello,

    So I have 2 S&F forms on my pages (different results pages). Is it possible to pass the query from my main text search to a sidebar filters S&F form I have? The filters on the left live on results page from the main search bar, and if you try to use them they reset the query from the text search (which makes sense technically). I am wondering if there is a way that if a user hits ones of those filters I can pass the query from the other S&F form?

    I saw this:

    function filter_function_name( $query_args, $sfid ) {

    if ( is_search() ) {
    //var_dump($sf_current_query);
    }

    //if search form ID = 225, the do something with this query
    if($sfid==225)
    {
    //modify $query_args here before returning it
    $query_args[‘somearg’] = ‘newvalue’;
    }

    return $query_args;
    }
    add_filter( ‘sf_edit_query_args’, ‘filter_function_name’, 20, 2 );

    But wasn’t sure if that was the right path to grab the current query and pass it along to the other form.

    Thank you!

    Trevor Moderator
    #256289

    If you are on the results page, the two forms will not ‘talk’ to each other. You would probably be better to use JavaScript. I assume one is the Text Search, and one the rest of the filters? In V3 (due in a few months), we plan to allow you to split a form up which would have the same effect as you want.

    For now, you would be better to hide the one form and add a Text box to the other on the results page.

    Danny Albeck
    #256294

    Hey Trevor,

    Yes, that is correct. The main global search form drives to a custom search template, where the filters that are in the sidebar use a Custom results method.

    The sidebar filters currently do not have a text search box in them, but are you suggesting that I could use a little bit of JS to grab the current query from the main search bar, and put that value in a hidden text field in the sidebar filters?

    If that is correct to assume, that will for sure work for now until v3 is out and we can re-factor.

    Appreciate the fast support as always!

    Trevor Moderator
    #256298

    You can use a wordpress rewrite to point a theme global search to our form. There is an example here (the site shown uses a slug name for the search results page, which looks nicer):

    https://support.searchandfilter.com/forums/topic/using-default-wp-search-bar-to-show-sf-results-page/#post-243811

    Here there is an example of one that doesn’t use a slug:

    https://support.searchandfilter.com/forums/topic/how-to-maintain-search-string-while-filtering/#post-205209

    Danny Albeck
    #256322
    This reply has been marked as private.
    Trevor Moderator
    #256394

    Ah, let us focus on the sidebar search, as that should be you main search (but, I would normally have the header search, if one of our forms, set to Custom, using the same URL as the sidebar search, with Ajax OFF, and NOT use the guidance I sent you in the previous message, as this header search is NOT the theme search).

    That sidebar search should have a text search box in it, so that, when the search from the header search arrives on that page (now set in that header search form as it is now set to Custom, with that results URL).

    On the results page, I would hide the header search. If you inspect the results page, in the body tag, will be a class name for the page (e.g. page-id-1234) which you can use to conditionally hide it).

    Danny Albeck
    #256443

    This resolved the issue. Thank you!

    Trevor Moderator
    #256449

    Thanks for letting me know. I will close this thread for now.

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

The topic ‘Pass Search Query to another instance of S&F’ is closed to new replies.