I want to change the class when choosing a checkbox inside the repeater. I do this with a switch case
, but I cannot get the checkboks value outside while
. How do I get the checkbox array out of while
correctly?
ACF
$checkboxarray = get_field('sy_color');
Code:
<div class="loop solution-include-pages d-flex">
<?php
if (have_rows('support_you')) {
$checkboxarray = get_field('sy_color');
foreach ($checkboxarray as $value) {
switch ($value) {
case 'red':
$class = 'rose-c';
break;
case 'green':
$class = 'green-c';
break;
case 'blueberry':
$class = 'blueberry-c';
break;
}
while (have_rows('support_you')) {
the_row();
$sy_img = get_sub_field('sy_img');
$sol_img = wp_get_attachment_image_src( $sy_img, 'full', true );
$sy_header = get_sub_field('sy_header');
$sy_content = get_sub_field('sy_content');
$sy_link = get_sub_field('sy_link');
$sy_color = get_sub_field('sy_color');
?>
<div class="sol-item d-flex flex-direction">
<div class="sol-item-img">
<img src="<?php echo $sol_img[0];?>" class="img-responsive" alt="">
</div>
<div class="sol-content">
<div class="sol-content-header <?php echo $class; ?>">
<?php echo $sy_header; ?>
</div>
<div class="sol-content-text">
<?php echo $sy_content; ?>
</div>
<a href="<?php echo $sy_link;?>" class="bluberry-btn item-center">Learn more</a>
</div>
</div>
<?php
}
}
}
?>
</div>
Acf checkboks option:
get_sub_field()
instead ofget_field()
– denisey