Forums › Forums › Search & Filter Pro › Pass Search Query to another instance of S&F
Tagged: multiple forms, pass query, V3
- This topic has 7 replies, 2 voices, and was last updated 4 years, 3 months ago by Trevor.
-
Anonymous(Private) August 17, 2020 at 7:34 am #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(Private) August 17, 2020 at 4:35 pm #256289If 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.
Anonymous(Private) August 17, 2020 at 4:44 pm #256294Hey 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(Private) August 18, 2020 at 10:42 am #256394Ah, 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).
-
AuthorPosts