Home › Forums › Front-end Issues › Mutliple choice checkbox, add a class › Reply To: Mutliple choice checkbox, add a class
What is the return value of the field set to? Your code assumes values, but you might want to check it. It could be somewhere in you if/elseif statements.
I would simplify it like this
<?php
if (have_rows('add_info_exam_grid')) {
$addclassexamgrid = array();
$checkboxarray = get_field('add_age_exam_grid');
foreach ($checkboxarray as $value) {
switch ($value) {
case 'Option1':
$addclassexamgrid[] = 'class1';
break;
case 'Option2':
$addclassexamgrid[] = 'class2';
break;
case 'Option3':
$addclassexamgrid[] = 'class3';
break;
} // end switch
while (have_rows('add_info_exam_grid')) {
the_row();
?>
<div class="grid-item <?php echo implode(' ', $addclassexamgrid); ?> col-md-4 col-sm-6 col-xs-12">
//Some code here
</div>
<?php
} // end while have_rows
} // end foreach
} // end if 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 Cookie Policy. If you continue to use this site, you consent to our use of cookies.