For all my AFC fields I’m using a php if statement so that if the field is empty, the entire section containing the field data won’t be loaded, for example:
<?php if( get_field('client_intro') ): ?>
<section id="client-intro">
<div class="wrapper">
<p><?php echo get_field('client_intro'); ?></p>
</div>
</section>
<?php endif; ?>
I wanted to do the same thing with a section that contains shortcode data but I can’t figure out what to use. The shortcode is used by a plugin that displays posts, so I tried this (and many others):
<?php if( have_posts() ): ?>
<section id="client-posts">
<div class="wrapper">
<?php echo do_shortcode('[display-posts posts_per_page="10"]'); ?>
</div>
</section>
<?php endif; ?>
Nothing works, the section still loads even without posts. Simply speaking I only want the #client-posts section to load if there are posts, if no posts, don’t load.