Forums › Forums › Search & Filter Pro › Showing the search query
- This topic has 6 replies, 2 voices, and was last updated 7 years, 8 months ago by Anonymous.
-
Anonymous(Private) February 21, 2017 at 9:50 pm #91803
I can’t seem to get the search query to show on my page. It does persist in the search box but Ideally I’d like to add a title to the page saying “You searched for…”
Echoing out the get_search_query(); isn’t returning anything. I’ve tried it both inside and outside of the loop.
It’s a pretty simple template …. here’s what I have:
<?php get_header(); ?> <?php if ( have_posts() ) : ?> <?php $search_query = get_search_query(); ?> <?php print_r($search_query);?> <div id="thumbnails"> <?php while ( have_posts() ) : the_post();?> <?php // Get the Post category $categories = get_the_category(); $className = strtolower(esc_html( $categories[0]->name )); ?> <div class="thumbnail <?php echo $className;?>"> <a class="thumbnail-link" href="<?php the_permalink();?>"> <div class="thumbnail-overlay-text"> View Image </div> </a> <?php the_post_thumbnail('thumbnail'); ?> </div> <?php endwhile; ?> </div> <?php endif; ?> <?php get_footer(); ?>
Trevor(Private) February 22, 2017 at 9:17 pm #92106You 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(Private) February 22, 2017 at 11:08 pm #92142OK 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; ?>
-
AuthorPosts