Forums Forums Search & Filter Pro Pass custom search input to S&F form and disable default ?s=

Viewing 9 posts - 1 through 9 (of 9 total)
  • Anonymous
    #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_s instead?

    Anonymous
    #215154

    I 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' );
    Trevor
    #215204

    That is the way to go. Obviously, if you have a shop and products is what you are searching, otherwise the URL part might need some changes.

    Anonymous
    #215211

    All 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 /shop page 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.

    Trevor
    #215216

    I am not sure that I understand. When the ‘standard’ search arrives on the shop page, do you mean you wan that term in the form already there? Does that form have a search box in it?

    Anonymous
    #215232

    Correct, 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/9EHxtEl

    The 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?

    Trevor
    #215234

    Ah, I understand. The two forms, when on the results page, will not ‘talk’ to each other. A solution for this will be coming in V3.

    Anonymous
    #215242

    I am on /about. I search, I end up on /shop/?_sf_s=test

    I search again, and without refreshing, it simply uses ajax as the S&F search input normally would too.

    Anonymous
    #215244

    Ah, I understand. The two forms, when on the results page, will not ‘talk’ to each other. A solution for this will be coming in V3.

    Ah ok! Great, thanks.

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