Forums › Forums › Search & Filter Pro › "Search field" displays all results when the term isn't found
- This topic has 7 replies, 2 voices, and was last updated 7 years, 9 months ago by Trevor.
-
Anonymous(Private) February 20, 2017 at 4:47 pm #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(Private) February 20, 2017 at 4:51 pm #91473Ooops. 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"; } } ?>
-
AuthorPosts