Home › Forums › Add-ons › Flexible Content Field › Reuse layout multiple times on page › Reply To: Reuse layout multiple times on page
This is not an error in the flex field, but in your logic. You are only setting a new value for the 3 variables if the field has a value, but you not resetting or unsetting the previous value it in the next iteration of the loop.
<?php
if( have_rows('content') ):
while ( have_rows('content') ) : the_row();
if ( get_row_layout() == 'textblock' ):
$title = '';
if( get_sub_field('title') ):
$title = get_sub_field( 'title' );
endif;
$lead = '';
if( get_sub_field('lead') ):
$lead = get_sub_field( 'lead' );
endif;
$body = '';
if( get_sub_field('body') ):
$body = get_sub_field( 'body' );
endif;
?>
<section class="textblock">
<?php echo $title ?>
<?php echo $lead ?>
<?php echo $body ?>
</section>
<?php
else :
endif;
?>
<?php
endif;
endwhile;
endif;
?>
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.