Home › Forums › Add-ons › Flexible Content Field › Post Based On Condition of Field › Reply To: Post Based On Condition of Field
I think I see what you mean and what you’re trying to do. No you wouldn’t need to use an && check, but it is worth separating the checks and outputs to only the bits they need to control, which will make it a lot clearer for you.
What I think you’re trying to do is output $text on the left and $texts on the right. However your IF statements are exclusively saying
if $cols == 1 show me $text
if $cols == 2 show me $texts
Whereas what you want is:
if $cols == 1 show me $text
if $cols == 2 show me $text and show me $texts
To adapt my code slightly above, this would be:
<?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(); ?>
<div class="entry-header">
<h1 class="entry-title"><?php the_title(); ?></h1>
</div>
if( get_row_layout() == 'blue_content_blocks' ) :
if( $cols == "1") : ?>
<div>
<?php echo $title; ?>
<?php echo $text; ?>
</div>
<?php elseif( $cols == "2") : ?>
<div class="blue">
<div class="col-sm-6">
<?php echo $title; ?>
<?php echo $text; ?>
</div>
<div class="col-sm-6">
<?php echo $texts; ?>
</div>
</div>
<?php endif;
endif; //get_row_layout
endwhile; //have_rows
endif; //have_rows
?>
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.