Forums Forums Search & Filter Pro "Search field" displays all results when the term isn't found

Viewing 8 posts - 1 through 8 (of 8 total)
  • Anonymous
    #91472

    Thank you very much for such a nice plugin. It works like charm and we are very happy with it! Up until now we have managed to sort out all the little problems we’ve had by reading the forum, but I can’t find a solution to this one.

    I have added a “Search field” to my form and, whenever I deliberately look for a term that doesn’t exist, instead of displaying the “No results found” message, it returns all the items unfiltered. Is there a way to solve this?

    It may have something to do with my results .php, which I have edited quite a bit, but I’m not sure. This is the code I’m using for it:

    [code]
    <?php
    /**
    * Search & Filter Pro
    *
    * Sample Results Template
    *
    * @package Search_Filter
    * @author Ross Morsali
    * @link http://www.designsandcode.com/
    * @copyright 2015 Designs & Code
    *
    * Note: these templates are not full page templates, rather
    * just an encaspulation of the your results loop which should
    * be inserted in to other pages by using a shortcode – think
    * of it as a template part
    *
    * This template is an absolute base example showing you what
    * you can do, for more customisation see the WordPress docs
    * and using template tags –
    *
    * http://codex.wordpress.org/Template_Tags
    *
    */

    global $searchandfilter;
    $sf_current_query = $searchandfilter->get(21899)->current_query();
    if ((!$sf_current_query->is_filtered())&&($sf_current_query->get_search_term()==””)) {
    echo ‘<div> </div>’;
    } else {

    if ( $query->have_posts() )
    {
    ?>

    Se han encontrado <?php echo $query->found_posts; ?> resultados<br />

    <?php
    while ($query->have_posts())
    {
    $query->the_post();

    ?>
    <div class=’search-filter-results-list’>
    “><h2 class=’search-filter-title’><?php the_title(); ?></h2>

    <?php
    if ( has_post_thumbnail() ) {
    echo ‘<div class=”menu-img”>’;
    the_post_thumbnail(“full”);
    echo ‘</div>’;
    }
    ?>
    </div>

    <?php
    }
    ?>
    <?php
    }
    else
    {
    echo “No se han encontrado resultados”;
    }
    }
    ?>
    [/code]

    Anonymous
    #91473

    Ooops. I tried to create a code box with bbcode but it seems it doesn’t work here. Sorry for that! Here you have it again.

    <?php
    /**
     * Search & Filter Pro 
     *
     * Sample Results Template
     * 
     * @package   Search_Filter
     * @author    Ross Morsali
     * @link      http://www.designsandcode.com/
     * @copyright 2015 Designs & Code
     * 
     * Note: these templates are not full page templates, rather 
     * just an encaspulation of the your results loop which should
     * be inserted in to other pages by using a shortcode - think 
     * of it as a template part
     * 
     * This template is an absolute base example showing you what
     * you can do, for more customisation see the WordPress docs 
     * and using template tags - 
     * 
     * http://codex.wordpress.org/Template_Tags
     *
     */
    
    global $searchandfilter;
    $sf_current_query = $searchandfilter->get(21899)->current_query();
    if ((!$sf_current_query->is_filtered())&&($sf_current_query->get_search_term()=="")) {
      echo '<div> </div>'; 
    } else {
    	
    	if ( $query->have_posts() )
    {
    	?>
    
    	Se han encontrado <strong><?php echo $query->found_posts; ?> resultados</strong><br />
    	
    	<?php
    	while ($query->have_posts())
    	{
    		$query->the_post();
    		
    		?>
    		<div class='search-filter-results-list'>
    			<a href="<?php the_permalink(); ?>"><h2 class='search-filter-title'><?php the_title(); ?></h2>
    		
    			<?php 
    				if ( has_post_thumbnail() ) {
    					echo '<div class="menu-img">';
    					the_post_thumbnail("full");
    					echo '</div>';
    				}
    			?>			
    		</a></div>
    		
    		<?php
    	}
    	?>
    	<?php
    }
    else
    {
    	echo "No se han encontrado resultados";
    }
    }
    ?>
    Anonymous
    #91488
    This reply has been marked as private.
    Trevor
    #91539
    This reply has been marked as private.
    Anonymous
    #91678
    This reply has been marked as private.
    Trevor
    #91966

    I have made some changes to the form, can you check again?

    Anonymous
    #91999

    Yay! It works perfectly now! Having a look at the changes you’ve made, all I should do is uncheck every “Advanced option”, isn’t it?

    Thank you very much for your help! Please, feel free to close this thread.

    Trevor
    #92001

    You do not have the Relevanssi plugin installed, so that was not allowed (2 of those checkboxes). Forcing the is search doesn’t apply to your Display Result Method (I believe). I will close the thread now. Thanks for getting back to me.

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