Forums Forums Search & Filter Pro Redirection of empty search queries

Viewing 4 posts - 1 through 4 (of 4 total)
  • Anonymous
    #249557

    Hi,

    I redirect search queries as described here: https://support.searchandfilter.com/forums/topic/using-default-wp-search-bar-to-show-sf-results-page/#post-243811 It works fine, but I discovered today that redirection doesn’t work when an empty search query is entered. Is there any way to change that?

    Thanks

    Trevor
    #249558

    MMM. Maybe:

    function sandf_change_search_url_rewrite() {
    	$search_string = "";
    	if ( is_search() ) {
    		if (! empty( $_GET['s'] ) ) {
    			$search_string = urlencode( get_query_var( 's' ) );
    		}
    		wp_redirect( home_url( "search-results/?_sf_s=" ) . $search_string );
    		exit();
    	}	
    }
    add_action( 'template_redirect', 'sandf_change_search_url_rewrite' );

    That might work.

    Anonymous
    #249567

    Works fine. Thank you.

    Trevor
    #249569

    Thanks for getting back to me. I will close this thread for now.

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