Forums Forums Search & Filter Pro get_search_query stops working with Relevannsi enabled

Viewing 10 posts - 1 through 10 (of 14 total)
  • Anonymous
    #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,
    Nathan

    Trevor
    #249104

    Posting the code inside code back ticks (one before, one after, it is the key next to the 1 on my keyboard) can you send me the code that you are using? It is not necessary to send the whole file, just the part relating to the query.

    Anonymous
    #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
    #249146

    Your use of get_search_query() does not appear to relate to the use of our plugin, so is your issue not with Relevanssi?

    Anonymous
    #249191

    The problem only appears to be happening with S&F search bars. I’ve included a link to a working example below.

    I’ve added an S&F search and a default WP search bar on the page so you can test each one.
    You can use “salt” as your search term.

    http://inyoblog2.azurewebsites.net/blog/

    Trevor
    #249201

    Can 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.

    Anonymous
    #249214

    It’s showing the following:
    Array
    (
    )

    capture

    Trevor
    #249221

    Ah. 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>'; 
    }
    Anonymous
    #249228

    I’m testing on my localhost so I’m replacing the id with the correct form id. Here is what it shows now:

    capture

    Trevor
    #249230

    Whoops:

    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>'; 
    }
Viewing 10 posts - 1 through 10 (of 14 total)