Support

Account

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
    ?>