I'm still trying to wrap my head around PHP (no pun intended) and am trying to get something to work using the Advanced Custom Fields plugin in WordPress.
So, I've got a repeater field that's made up of two Number Fields and a True/False field. I'm basically trying to write a statement like this:
If the True/False field is true
then echo
both sub_field_1
and sub_field_2
, else echo just sub_field_1
.
So far, I've got this:
<?php
while(has_sub_field('parent_repeater')) {
if( the_sub_field('true') ) {
echo '<p>' . get_sub_field('sub_field_1') . get_sub_field('sub_field_2') . '</p>';
}
else {
echo '<p>' . get_sub_field('sub_field_1') . '</p>';
}
}
?>
What am I doing wrong? I'm currently going through the ACF documentation, if anyone could point me in the right direction, I'd really appreciate it.
Thanks in advance!
EDIT:
<ul class="list">
<?php while ( have_rows('blend') ) : the_row(); ?>
<?php
$field = get_sub_field_object('blend');
$value = the_sub_field('blend');
$label = $field['choices'][ $value ];
?>
<li>
<span>Pct: <?php the_sub_field('percentage'); ?> Mix: <?php the_sub_field('mix'); ?></span>
</li>
<?php endwhile; ?>
</ul>
<?php else :
echo '<p>No Rows found</p>';
endif; ?>