Home › Forums › Add-ons › Flexible Content Field › Post Based On Condition of Field › Reply To: Post Based On Condition of Field
Based on the code and the ACF field setup in your other post, this should work for you:
<?php
$title = get_sub_field('title');
$text = get_sub_field('text');
$texts = get_sub_field('text_copy');
$cols = get_sub_field('columns');
<?php
// check if the flexible content field has rows of data
if( have_rows('text_section') ):
while ( have_rows('text_section') ) : the_row();
if( get_row_layout() == 'blue_content_blocks' ) :
if( $cols == "1") : ?>
<div>
<?php echo $title; ?>
<?php echo $text; ?>
</div>
<?php elseif( $cols == "2") : ?>
<div class="col-sm-6">
<?php echo $title; ?>
<?php echo $texts; ?>
</div>
<?php endif;
endif; //get_row_layout
endwhile; //have_rows
endif; //have_rows
?>
Edit: variable name typo
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.