Home › Forums › Front-end Issues › Hide Repeater Filed Row if empty
Hi
I have a CPT with a Repeater Filed called files
.
This Repeater Field contains only a sub-filed (a Text filed) called file
.
There Repeater Fields I set are in total 10 and are populated from somewhere outside the website and sometimes some rows are not populated and stay empty. This cannot be changed.
For example in one post only 3 rows have value but the rest are empty.
In front end I am getting the values in a slider. It works, but also the empty fields are rendered and if the row is empty it shows a missing file (images in my case).
How can I hide empty fields taking in consideration the code below?
<?php if( have_rows('files') ): ?>
<div class="slider">
<div class="container">
<div id="slider-basic" class="slider slide" data-ride="carousel">
<!-- Indicators -->
<ol class="carousel-indicators">
<?php
$active = 'active';
$num = 0;
while ( have_rows('files') ) : the_row();
?>
<li data-target="#slider-basic" data-slide-to="<?php echo $num ?>" class="<?php echo $active ?>"></li>
<?php
$active = '';
$num += 1;
endwhile; ?>
</ol>
<!-- Wrapper for slides -->
<div class="carousel-inner" role="listbox">
<?php
$active = 'active';
while ( have_rows('files') ) : the_row();
?>
<div class="carousel-item <?php echo $active ?> special">
<div class="container">
<img src="<?php echo get_template_directory_uri(); ?>/files/images/<?php the_sub_field('file'); ?>" />
</div>
</div><!-- /item -->
<?php $active = '';
endwhile;
?>
</div>
</div>
</div>
</div><!-- /row -->
<?php endif; ?>
Many thanks in advance!
before outputting the line item in each loop
if (empty(get_sub_field('file'))) {
continue;
}
You must be logged in to reply to this topic.
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.