Forums › Forums › Search & Filter Pro › No Results Found With Filter
- This topic has 7 replies, 2 voices, and was last updated 6 years ago by
Trevor.
-
Trevor(Private) August 16, 2019 at 10:46 am #219117
If you need to modify our results.php template the guide is here:
https://searchandfilter.com/documentation/search-results/using-a-shortcode/#customising-the-results
If you need to output the value of an ACF field, and give it a label, the code shown in this post might help:
You may find other posts with snippets with this forum search:
https://support.searchandfilter.com/forums/search/results.php+acf+get_field/
Anonymous(Private) September 4, 2019 at 8:44 pm #220320Thanks! That worked well.
Just out of curiosity, my code works but I have such a rudimentary understanding of PHP I only want the fields “image” and “business_description” to display if it exists. This is what I got. How can I add that in or is there some post I can look at to figure it out. `<?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
$header_link = the_field(‘business_website_address_url’);
?><?php
while ($query->have_posts())
{
$query->the_post();?>
<div>
<h2><a href=”<?php the_field(‘business_website_address_url’); ?>”><?php the_title(); ?></a></h2>
<div class=”desc”><img src=”<?php the_field(‘image’); ?>”><p><?php the_field(‘business_description’) ?></p></div>
<p class=”details”> Website: <a href=”<?php the_field(‘business_website_address_url’); ?>” target=”_blank”><?php the_field(‘business_website_address_url’) ?></a></p>
<p class=”details”> Phone: <a href=”tel:<?php the_field(‘phone’); ?>”><?php the_field(‘phone’) ?></a></p>
<p class=”details”> Booth: <?php the_field(‘booth_number’) ?></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( ‘More Exhibitors’, $query->max_num_pages ); ?></div>
<div class=”nav-next”><?php previous_posts_link( ‘Previous Exhibitors’ ); ?></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”;
}
?>`Trevor(Private) September 6, 2019 at 9:04 am #220392So, if I understand you correctly, you want to conditionally show this part:
<div class="desc"><img src="<?php the_field('image'); ?>”><p><?php the_field('business_description') ?></p></div>
so, it would be this:
<?php if (get_field('image')) {?> <div class="desc"><img src="<?php the_field('image'); ?>”><p><?php the_field('business_description') ?></p></div> <?php }?>
This uses get_field to see if the image field has anything in it, and only outputs that bit if it does. I am assuming here that if the image exists, so will the description.
I hope that helps?
-
AuthorPosts