Forums › Forums › Search & Filter Pro › Pass custom search input to S&F form and disable default ?s=
- This topic has 8 replies, 2 voices, and was last updated 6 years, 9 months ago by
Anonymous.
-
Anonymous(Private) June 27, 2019 at 5:10 pm #215149
I am adding a search input in the header of my website, I have set the following so when a search is made, it uses the S&F search query tag
name="_sf_s".https://example.co.uk/shop/?_sf_s=tempora
This takes me to my shop which has the S&F form on, the form input picks up the value the user typed which is great, however I am wondering what to do about the default
?s=. Do you have a filter to disable people using the original?s=and it automatically changing the search to go through?_sf_sinstead?Anonymous(Private) June 27, 2019 at 5:22 pm #215154I found a function immediately after posting, Trevor/Ross, thoughts on this approach?
/** * Override the default search query and pass to S&F custom query */ function change_search_url() { if ( is_search() && ! empty( $_GET['s'] ) ) { wp_redirect( home_url( "/shop/?_sf_s=" ) . urlencode( get_query_var( 's' ) ) ); exit(); } } add_action( 'template_redirect', 'change_search_url' );Anonymous(Private) June 28, 2019 at 11:50 am #215211All good Trevor, thanks.
Any idea how I can pass/use my custom (separated from S&F form) search input to the S&F form when on the same page as the S&F form with results being loaded with Ajax?
When you search using my custom search input, you end up on the
/shoppage which has the S&F form on. That form is set up to load results with Ajax.Currently if you type a new search in my custom search input, it will reload the page with the new search value:
/shop/?_sf_s=hello. I want to have it trigger the form to do a new ajax reload.Anonymous(Private) June 28, 2019 at 2:54 pm #215232Correct, the search in my header is a standard <input type=”search”> seperate from the S&F form.
When you’re on the /shop page which contains the S&F form, and you still choose to use the search bar in the header, it should reload the results using ajax, the same as how it does when you use the search input which is within the S&F form.
Here is a screenshot:
https://imgur.com/a/9EHxtElThe search input at the top is a custom <form> etc. The search in the left sidebar is the one loaded by S&F. I may or may not keep both don’t know yet, but regardless it would be good for the top one to be connected to S&F form if possible when on the same page. If understood?
-
AuthorPosts