Home › Forums › ACF PRO › Repeater: Hide output if sub_field is empty › Reply To: Repeater: Hide output if sub_field is empty
I solved this for anyone else that has the same problem. It was basically my ignorance and oversight:
<section id="awards">
<?php if( have_rows('award_images', 'options', true) ): ?>
<div class="container">
<div class="row">
<h2 class="awards text-center"><span>Awards</span></h2>
<div class="awards-wrap col-md-12">
<ul class="awards">
<?php
while( have_rows('award_images', 'options', true) ): the_row();
// vars
$award_image = get_sub_field('award_image');
$award_image_link = get_sub_field('award_image_link');
?>
<li class="award">
<?php if( $award_image_link ): ?>
<a href="<?php echo $award_image_link; ?>">
<?php endif; ?>
<img src="<?php echo $award_image['url']; ?>" alt="<?php echo $award_image['alt'] ?>" />
<?php if( $award_image_link ): ?>
</a>
<?php endif; ?>
</li>
<?php endwhile; ?>
</ul>
</div>
</div>
</div>
<?php endif; ?>
</section>
I just moved the if (have_rows() ) line inside the section element. 🙂
Welcome to the Advanced Custom Fields community forum.
Browse through ideas, snippets of code, questions and answers between fellow ACF users
Helping others is a great way to earn karma, gain badges and help ACF development!
We use cookies to offer you a better browsing experience, analyze site traffic and personalize content. Read about how we use cookies and how you can control them in our Privacy Policy. If you continue to use this site, you consent to our use of cookies.