Forums Forums Search & Filter Pro Showing the search query

Viewing 6 posts - 1 through 6 (of 6 total)
  • Anonymous
    #91984

    Still Trying to get this to work to no avail. The WordPress default
    get_search_query();
    returns nothing.

    Trevor
    #92106

    You need instead to use code like this to get the query:

    global $searchandfilter;
    $sf_current_query = $searchandfilter->get(339)->current_query();

    Where 339 is the form ID.

    You might need to dump the array to get an idea what is in it, but a search of the forum reveals some code snippets:

    https://support.searchandfilter.com/forums/search/sf_current_query+searchandfilter+current_query/

    I think it is possible that the next major release (V3, which we are working on right now) will have a much better way of doing this).

    Anonymous
    #92142

    OK thats I got it.

    For anyone else who stumbles across this here’s the full code to output the Search Query

    Firstly this gets the Query (change number to your search form ID) – place in the loop in your template:

    global $searchandfilter;
      $sf_current_query = $searchandfilter->get(54)->current_query();
      $searchTerm = $sf_current_query->get_search_term();

    and then you can echo out the query in your anywhere in your template
    <?php echo $sf_current_query; ?>

    Anonymous
    #92146

    Opps sorry that second line should be:

    <?php echo $searchTerm; ?>

    Trevor
    #92152

    I can close this thread?

    Anonymous
    #92177

    Sure can!

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