I’m having trouble with the repeater field, it still outputs the code the between <?php if(have_rows('image_slideshow')): ?>
despite there being no rows of data. i.e the <div class="section-intro">
and the other divs
enclosed are still output as HTML to the page. My understanding was <?php if(have_rows('image_slideshow')): ?>
checks if there is data and if it’s true then the code gets output. How can I set up a conditional statement that only outputs the code if there is data in either/or both the $image
and $center_text
fields?
<?php if(have_rows('image_slideshow')): ?>
<div class="section-intro">
<div class="slides owl-carousel">
<?php while( have_rows('image_slideshow') ): the_row();
$image = get_sub_field('image');
$content = get_sub_field('centered_text');
?>
<div class="slide intro"
<?php if(!empty($image)): ?>
style="background-image: url('<?php echo $image['url']; ?>')"
<?php endif; ?>
>
<?php echo $content; ?>
</div>
<?php endwhile; ?>
</div>
</div>
<?php endif; ?>
Hi @cnd, did you get this sorted?
When I experimented with the code you provided the conditional worked fine on my end. What is your repeater field attached or connected to?