Hiding empty field within ACF Repeater loop
-
I’m using ACF Pro repeater field on this page: https://www.test.truetolifetraining.com/colleges-universities
Within each content block, there’s an option to add an image or a video. When the video field is left blank, it’s fine, however, when the image field is left blank, a tiny square shows up above the video.
I’m trying to figure out how to hide the image field if it is left blank, but I’m not sure how to do that within a repeater. Here’s the code from my page template:
<?php if( have_rows('content_block') ): ?> <?php while( have_rows('content_block') ): the_row(); // vars $title = get_sub_field('title'); $content = get_sub_field('content'); $image = get_sub_field('image'); $video = get_sub_field('video'); ?> <div class="content-block-item"> <div class="content-block-inner"><h4> <?php echo $title; ?></h4> <p><?php echo $content; ?></p> <div class="content-block-photo"><img src="<?php echo $image['url']; ?>"/></div> <div class="video"><?php echo $video;?></div> <button><a href="mailto:[email protected]">get in touch to learn more</a></button> </div> </div> <?php endwhile; ?> <?php endif; ?>
Viewing 5 replies - 1 through 5 (of 5 total)
Viewing 5 replies - 1 through 5 (of 5 total)
- The topic ‘Hiding empty field within ACF Repeater loop’ is closed to new replies.