Forums Forums Search & Filter Pro Search variable ?s= versus _sf_s

Viewing 3 posts - 1 through 3 (of 3 total)
  • Anonymous
    #29533

    Hi Ross,

    I found a minor problem with the renaming of the search variable to ‘_sf_s’ and need your input on a possible solution.

    The problem: Some searches on our site use the default WP search box (for various reasons we can’t use the S&F Pro search box). Results are displayed on the standard search.php template, and on the search results page we have our Filters setup. One of the filters is to start a ‘new search’ using an S&F Pro search box.

    If a person then starts a new search, the page does not display the new search term, because the template is setup to display the search term using this PHP snippet:

    <?php printf( esc_html__( ‘Search Results for: %s’, ‘quark’ ), ‘<span>“’ . get_search_query() . ‘”</span>’ ); ?>

    As you can see, the search term is represented by %s, which comes initially from the original search (so that when they first hit the results page they see “Search Results for: [whatever their original search term is]”

    SO can I add a variable to replace that %s and use an array that encompasses both ?s= and _sf_s ?

    Something like

    $x = array(‘?s=’,’_sf_s’) and then change %s to %x ?

    I’m not a coder, but I need to find a way for search terms to be displayed to the searcher when they get to the results page from a WP search as well as a S&F Pro filter…….

    Your thoughts?

    Thanks,
    Trisha

    Ross Moderator
    #29536

    Hey Trisha

    Something like this should work:

    <?php 
    	$search_term = "";
    	
    	//get global S&F object
    	global $searchandfilter;
    	$current_query = $searchandfilter->get(1526)->current_query();
    	
    	//check to see if a term has been found under the regular WP variable
    	//if not, try the S&F object
    	
    	if(get_search_query()!="")
    	{
    		$search_term = get_search_query();
    	}
    	else if($current_query->get_search_term()!="")
    	{
    		$search_term = $current_query->get_search_term();
    	}
    	
    	printf( esc_html__( 'Search Results for: %s', 'quark' ), '<span>"' . $search_term . '"</span>' ); 
    	
    ?>

    I didn’t test it yet but looks sound.

    Thanks

    Anonymous
    #29573

    Thanks Ross – that worked perfectly!!!

    🙂

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