Home › Forums › Add-ons › Repeater Field › Display a field only if populated › Reply To: Display a field only if populated
Hi @Permanence
Have you read the code exmaples for conditional logic / understand what an if statement in PHP is?
Your code should look more like this:
<?php while(the_repeater_field('content_block')): ?>
<div class="clearfix">
<?php if( get_sub_field('title') ): ?>
<h2><?php the_sub_field('title'); ?></h2>
<?php endif; ?>
<div class="img"><img src="<?php the_sub_field('image'); ?>"></div>
<div class="txt"><?php the_sub_field('content'); ?> </div>
</div>
<?php endwhile ?>
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.