Forums › Forums › Search & Filter Pro › get_search_query stops working with Relevannsi enabled
Tagged: get_search_query, relevannsi
- This topic has 13 replies, 2 voices, and was last updated 4 years, 6 months ago by Trevor.
-
Anonymous(Private) June 16, 2020 at 9:22 pm #249050
Hi,
When I enable Relevannsi in the advanced options, my search results page no longer displays the current search term using get_search_query().
It works fine as long as relevannsi is turned off.Any thoughts on why this might be happening?
Thanks,
NathanAnonymous(Private) June 17, 2020 at 1:59 pm #249127<!--Display Search & Filter Widget --> <?php if (is_active_sidebar('search-bar')) : ?> <div id="search-bar" role="complementary"> <?php dynamic_sidebar('search-bar'); ?> </div> <?php endif; ?> <header id="search-title"> <h3 class="page-title"> <?php printf( /* translators: %s: query term */ esc_html__('Search Results for: %s', 'understrap'), '<span>"' . get_search_query() . '"</span>' ); ?> </h3> </header><!-- .page-header --> <div class="row"> <!-- Do the left sidebar check and opens the primary div --> <?php get_template_part('global-templates/left-sidebar-check'); ?> <main class="site-main" id="main"> <?php if (have_posts()) : ?> <div class="card-columns"> <?php /* Start the Loop */ ?> <?php while (have_posts()) : the_post(); ?> <?php //Display search results based on content type. //To change how different content types are displayed in search, edit the content-search loop template. get_template_part('loop-templates/content', 'search'); ?> <?php endwhile; ?> </div><!--Card Column--> <?php else : ?> <?php /* If the search term does not exist in the current category, a custom query will be intiated to display other content types that match the search term. */ if (is_category('videos')) { $custom_query_args = array( 'category_name' => 'articles,htg', 'posts_per_page' => -1, 's' => get_search_query() ); } elseif (is_category('articles')) { $custom_query_args = array( 'category_name' => 'videos,htg', 'posts_per_page' => -1, 's' => get_search_query() ); } elseif (is_category('htg')) { $custom_query_args = array( 'category_name' => 'articles,videos', 'posts_per_page' => -1, 's' => get_search_query() ); } else { $custom_query_args = array( 'category_name' => 'articles,videos,htg', 'posts_per_page' => -1, 's' => get_search_query() ); } $custom_query_args['paged'] = get_query_var('paged') ? get_query_var('paged') : 1; $custom_query = new WP_Query($custom_query_args); // Output custom query loop if ($custom_query->have_posts()) : if (is_category('Videos')) { printf('<h5>Sorry, we don\'t have any videos that match your search. Here is some other content that might interest you.</h5>'); } elseif (is_category('Articles')) { printf('<h5>Sorry, we don\'t have any articles that match your search. Here is some other content that might interest you.</h5>'); } elseif (is_category('How-To Guides')) { printf('<h5>Sorry, we don\'t have any how-to guides that match your search. Here is some other content that might interest you.</h5>'); } ?> <div class="card-columns"> <!-- Display search results based on the custom query. --> <?php while ($custom_query->have_posts()) : $custom_query->the_post(); get_template_part('loop-templates/content', 'search'); endwhile; ?> </div><!-- Card Columns --> <?php else : //If there is nothing that matches the custom query, display not 'found message'. printf('<h1>Nothing at the moment...</h1>'); printf('<h6>Sorry, we don\'t have any DIY resources that match your search as of now, but we\'re always working hard on creating new content! Head over to our <a href="http://www.inyopools.com/forum">forum</a> to submit a content suggestion, or if you need an answer right away, feel free to chat with one of our pool experts.</h6>'); endif; ?> <?php endif; ?> </main><!-- #main -->
Trevor(Private) June 17, 2020 at 5:14 pm #249201Can you try adding this code to the page, so you can see what the query is actually sending, if anything (it might actually give you the variable to use as well):
<?php global $searchandfilter; $sf_current_query = $searchandfilter->get(102003)->current_query()->get_array(); echo '<pre>',print_r($sf_current_query,true),'</pre>'; ?>
Please note that we are now closed for the day as it is late afternoon here in the UK, so my next reply may not be until tomorrow.
Trevor(Private) June 17, 2020 at 5:35 pm #249221Ah. What about this (I did get the form ID number right, yes?):
global $searchandfilter; $sf_current_query = $searchandfilter->get(102003)->current_query(); if (!$sf_current_query->get_search_term()=="") { echo '<div>$sf_current_query->get_search_term()</div>'; }
-
AuthorPosts