From your original code I would have had this:
<?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(233)->current_query();
if ((!$sf_current_query->is_filtered())&&($sf_current_query->get_search_term()=="")) {
echo '<div>Nothing to see here folks!</div>';
} else {
if ( $query->have_posts() )
{
?>
<?php
while ($query->have_posts())
{
$query->the_post();
?>
<article id="post-<?php the_ID(); ?>" <?php post_class(); ?>>
<a href="<?php the_permalink(); ?>" alt="<?php the_title(); ?>">
<h2><?php the_title(); ?></h2>
<?php if( get_field('summary_portfolio_description') ): ?>
<p><?php the_field('summary_portfolio_description'); ?></p>
<?php endif; ?>
<?php the_excerpt(); ?>
</a>
</article>
<?php
}
}
else
{
echo "<span id='no-results'>No results found, please try altering your search criteria.</span>";
}
}
?>
AnonymousInactive
Hi Trevor,
Thanks for the code, just to clarify my code before was working okay it was just when I added the additional lines for the feature that checks if the user has entered anything where it broke. This was my original 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
*
*/
if ( $query->have_posts() )
{
?>
<?php
while ($query->have_posts())
{
$query->the_post();
?>
<article id="post-<?php the_ID(); ?>" <?php post_class(); ?>>
<a href="<?php the_permalink(); ?>" alt="<?php the_title(); ?>">
<h2><?php the_title(); ?></h2>
<?php if( get_field('summary_portfolio_description') ): ?>
<p><?php the_field('summary_portfolio_description'); ?></p>
<?php endif; ?>
<?php the_excerpt(); ?>
</a>
</article>
<?php
}
}
else
{
echo "<span id='no-results'>No results found, please try altering your search criteria.</span>";
}
?>
I try adding your code above and it shows results but it also shows results when nothing has been entered and the user first lands on the page?
Does that make sense?
Thanks,
James
That does not look right. It might look like this:
<?php
/**
* Search & Filter Pro
*
* Sample Results Template
*
* @package Search_Filter
* @author Ross Morsali
* @link https://searchandfilter.com
* @copyright 2018 Search & Filter
*
* 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
*
*/
if ( $query->have_posts() )
{
?>
Found <?php echo $query->found_posts; ?> Results<br />
Page <?php echo $query->query['paged']; ?> of <?php echo $query->max_num_pages; ?><br />
<div class="pagination">
<div class="nav-previous"><?php next_posts_link( 'Older posts', $query->max_num_pages ); ?></div>
<div class="nav-next"><?php previous_posts_link( 'Newer posts' ); ?></div>
<?php
/* example code for using the wp_pagenavi plugin */
if (function_exists('wp_pagenavi'))
{
echo "<br />";
wp_pagenavi( array( 'query' => $query ) );
}
?>
</div>
<?php
while ($query->have_posts())
{
$query->the_post();
?>
<div>
<h2>"><?php the_title(); ?></h2>
<p><br /><?php the_excerpt(); ?></p>
<?php
if ( has_post_thumbnail() ) {
echo '<p>';
the_post_thumbnail("small");
echo '</p>';
}
?>
<p><?php the_category(); ?></p>
<p><?php the_tags(); ?></p>
<p><small><?php the_date(); ?></small></p>
</div>
<hr />
<?php
}
?>
Page <?php echo $query->query['paged']; ?> of <?php echo $query->max_num_pages; ?><br />
<div class="pagination">
<div class="nav-previous"><?php next_posts_link( 'Older posts', $query->max_num_pages ); ?></div>
<div class="nav-next"><?php previous_posts_link( 'Newer posts' ); ?></div>
<?php
/* example code for using the wp_pagenavi plugin */
if (function_exists('wp_pagenavi'))
{
echo "<br />";
wp_pagenavi( array( 'query' => $query ) );
}
?>
</div>
<?php
}
else
{
echo "No Results Found";
}
?>
Clearly you would need to replace this part:
https://www.screencast.com/t/uKLQ9ga4Qm
The really basic WordPress pagination is what you can see in the sample template files in our plugin folder, in a sub-folder called templates. Look in the results.php file for an example of pagination code:
https://www.screencast.com/t/e3246BUfki6
AnonymousInactive
Here I have to add something, I have several pages and in each one I use a different personalized filter, each page corresponds to a department of Colombia, therefore, what we are looking for, is that the search result only brings results from that department, that’s why, if you go to the next two pages, you can see that the filter results are different.
https://www.starpets.com.co/antioquia/
https://www.starpets.com.co/cundinamarca/
This I clarify, since after reviewing the help forum, I found this answer that you gave previously to a user https://support.searchandfilter.com/forums/topic/prevent-empty-search-fetching-results/#post -185868 but I do not know if it applies to my project, since here you indicate that you should replace the id of the page, but if there are several forms and each one has a different id, how can I achieve what you indicate?
and so the code of my results.php file is displayed:
<?php
/**
* Search & Filter Pro
*
* Sample Results Template
*
* @package Search_Filter
* @author Ross Morsali
* @link https://searchandfilter.com
* @copyright 2018 Search & Filter
*
* 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
*
*/
if ( $query->have_posts() )
{
?>
Found <?php echo $query->found_posts; ?> Results<br />
Page <?php echo $query->query['paged']; ?> of <?php echo $query->max_num_pages; ?><br />
<div class="pagination">
<div class="nav-previous"><?php next_posts_link( 'Older posts', $query->max_num_pages ); ?></div>
<div class="nav-next"><?php previous_posts_link( 'Newer posts' ); ?></div>
<?php
/* example code for using the wp_pagenavi plugin */
if (function_exists('wp_pagenavi'))
{
echo "<br />";
wp_pagenavi( array( 'query' => $query ) );
}
?>
</div>
<?php
while ($query->have_posts())
{
$query->the_post();
?>
<div>
<h2>"><?php the_title(); ?></h2>
<p><br /><?php the_excerpt(); ?></p>
<?php
if ( has_post_thumbnail() ) {
echo '<p>';
the_post_thumbnail("small");
echo '</p>';
}
?>
<p><?php the_category(); ?></p>
<p><?php the_tags(); ?></p>
<p><small><?php the_date(); ?></small></p>
</div>
<hr />
<?php
}
?>
Page <?php echo $query->query['paged']; ?> of <?php echo $query->max_num_pages; ?><br />
<div class="pagination">
<div class="nav-previous"><?php next_posts_link( 'Older posts', $query->max_num_pages ); ?></div>
<div class="nav-next"><?php previous_posts_link( 'Newer posts' ); ?></div>
<?php
/* example code for using the wp_pagenavi plugin */
if (function_exists('wp_pagenavi'))
{
echo "<br />";
wp_pagenavi( array( 'query' => $query ) );
}
?>
</div>
<?php
}
else
{
echo "No Results Found";
}
?>
I do not know if there is something wrong here too, because in the page where I’m trying to find the code, at the end of the results, this comes out:
global $searchandfilter; $sf_current_query = $searchandfilter->get(2101)->current_query(); if ((!$sf_current_query->is_filtered())&&($sf_current_query->get_search_term()==””)) { echo ‘
Nothing to see here folks!
‘; } else { // your template archive code/loop OR results.php code here }
AnonymousInactive
Hello. New user here.
I’m having trouble getting pagination AND filtering to work. It’s one or the other, not both.
I’m using filtering on a Custom Post Type Archive in a custom theme. I tried to adapt my code to work like the results.php file, but it kept failing on the pagenavi args.
wp_pagenavi( array( 'query' => $the_query ) );
<– this just kept killing the page.
So.. I tried to simplify the query so it was a little more basic, but no matter what I pass to the ‘query’ arg in wp_pagenavi, nothing works.
The problem here, is I need to alphabetize my unfiltered results by a custom_meta. I’ve tried to search through support and try a few things, but I’m not getting it to work.
This is the code I’m pulling into my archive-thoughtleaders.php via get_template_party :
<?php
$posts = get_posts(array(
'post_type' => 'thoughtleaders',
'posts_per_page' => 10,
'paged' => ( get_query_var('paged') ? get_query_var('paged') : 1 ),
'meta_key' => 'last_name',
'orderby' => 'meta_value',
'order' => 'ASC'
));
?>
<?php //$the_query = new WP_Query( $posts ); // the results.php file didn't have this.. BUT without this, the $the_query from results.php sample throws an error on pagenavi. But docs say don't use custom loops. this essentially breaks the filtering but makes pagination work. '?>
<?php if ( have_posts() ) : ?>
<?php if (function_exists('wp_pagenavi')) { ?>
<div class="pagination">
<?php wp_pagenavi( array( 'query' => $the_query ) ); ?>
<?php //wp_pagenavi(); ?>
</div>
<?php } ?>
<div class="leaderDirectory">
<?php while ( have_posts() ) : the_post(); ?>
<div class="leaderEntry">
<a href="<?php the_permalink(); ?>" title="<?php the_title(); ?>">
<?php if ( has_post_thumbnail() ) { ?>
<?php the_post_thumbnail('headshot-large');?>
<?php } else { ?>
<img src="https://via.placeholder.com/680x680" alt="" />
<?php } ?>
<div class="leaderEntryMeta">
<h4><?php the_title(); ?></h4>
<?php //the_excerpt(); ?>
<p><?php echo wp_trim_words( get_the_excerpt(), 20, '…' ); ?></p>
<p class="readMore">read more</p>
</div>
</a>
</div>
<?php endwhile; ?>
</div>
<?php if (function_exists('wp_pagenavi')) { ?>
<div class="pagination">
<?php wp_pagenavi( array( 'query' => $the_query ) ); ?>
<?php //wp_pagenavi(); ?>
</div>
<?php } ?>
<?php else : ?>
<p>No Results Found</p>
<?php endif; ?>
AnonymousInactive
Just an update for issue 3, I muddled my way through copying that results.php template. I’ve managed to make most of the changes I wanted to achieve. The results now only show the image (yay!) but you can’t click them haha.
Are you able to tell me how I would make the thumbnails clickable through to their respective posts? I tried and I broke it…
Also, would you know how to make it into 3 columns (that reduce to two, then one, when the window gets smaller) instead of one giant image after another vertically?
My PHP code is below.
<?php
/**
* Search & Filter Pro
*
* Sample Results Template
*
* @package Search_Filter
* @author Ross Morsali
* @link https://searchandfilter.com
* @copyright 2018 Search & Filter
*
* 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
*
*/
if ( $query->have_posts() )
{
?>
<?php
while ($query->have_posts())
{
$query->the_post();
?>
<div>
<?php
if ( has_post_thumbnail() ) {
echo '<p>';
the_post_thumbnail("small");
echo '</p>';
}
?>
</div>
<?php
}
?>
<?php
}
else
{
echo "No Results Found";
}
?>
Hi
This is an alternative exemplar results.php file content that might do as you want:
<?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
*
*/
if ( $query->have_posts() ) {
?>
Found <?php echo $query->found_posts; ?> Results<br />
<div class='search-filter-results-list'>
<?php
while ($query->have_posts())
{
$query->the_post();
?>
<div class='search-filter-result-item'>
<h2><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h2>
<p><br /><?php the_excerpt(); ?></p>
<?php
if ( has_post_thumbnail() ) {
echo '<p>';
the_post_thumbnail("small");
echo '</p>';
}
?>
<p><?php the_category(); ?></p>
<p><?php the_tags(); ?></p>
<p><small><?php the_date(); ?></small></p>
<hr />
</div>
<?php
}
?>
</div>
<?php
} else {
//figure out which type of "no results" message to show
$message = "noresults";
if(isset($query->query['paged'])) {
if($query->query['paged']>1){
$message = "endofresults";
}
}
if($message=="noresults") {
?>
<div class='search-filter-results-list' data-search-filter-action='infinite-scroll-end'>
<span>No Results Found</span>
</div>
<?php
} else {
?>
<div class='search-filter-results-list' data-search-filter-action='infinite-scroll-end'>
<span>End of Results</span>
</div>
<?php
}
}
?>
Hi Ryan
I think this very much abridged results.php file is all you need:
<?php
/**
* Search & Filter Pro
*
* Sample Results Template
*
* @package Search_Filter
* @author Ross Morsali
* @link https://searchandfilter.com
* @copyright 2018 Search & Filter
*
* 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
*
*/
if ( $query->have_posts() )
{
while ($query->have_posts())
{
$query->the_post();
if ( has_post_thumbnail() ) {
?>
<div>
<p><a href="<?php the_permalink(); ?>"><?php the_post_thumbnail("small"); ?></a></p>
</div>
<hr />
<?php
}
}
}
else
{
echo "No Results Found";
}
?>
It might cause you some CSS issues, I am not sure. However, much of the CSS you wrote to hide stuff would not be needed.
AnonymousInactive
I am really struggling to figure out how to display the search results on the same page within my template. I am not using the same theme but I believe I would be able to generally figure it out if given some sort of guidance. It’s incredibly frustrating to not be able to find any examples for replicating the demo beside what is provided. Code samples would be incredibly helpful!