Support

Account

Home Forums Add-ons Repeater Field Display a checkbox value within a repeatable field Reply To: Display a checkbox value within a repeatable field

  • Jason, when you are retrieving a value from a checkbox, it’s returned an array of value, since the check box can have multiple choices.

    Following your code above, since checkbox can have multiples values, sometimes when the user select 2 checkboxes your code will not work.

    I recommend you to use the option Radio Button, then the user can select only one option only. If you still want to continue with the checkbox, you can do it by this way:

    <?php if( have_rows('checkbox_repeater') ): ?>
    
    	<?php while ( have_rows('checkbox_repeater') ) : the_row(); ?>
    	
    		<?php 
    			$color = get_sub_field('checkbox');
    			$background = get_sub_field('background');
    			$content = get_sub_field('content');
    			echo "color = "; var_dump($color); // just for debugging 
    		 ?>
    		<br />
    		<br />
    		<section style="background-color:<? echo $background[0]; ?>; color: <?php echo $color[0]; ?>; height:40px; width:100%;">
    			<?php echo $content; ?>
    		</section><br /><br /><br />
    	
    	<?php endwhile; ?>
    <?php endif; ?>

    The result of this code is on the file annexed.

    If you want to know more about the checkbox field, you can check the docs.
    Here is the link:
    [CHECKBOX] http://www.advancedcustomfields.com/resources/checkbox/

    To display the radio button, you don’t need to specify the array number, because for radio buttons it’s returned a normal string.

    $radio_field = get_sub_field('radio');
    echo $radio_field; // returned: #CCCCCC
    var_dump($radio_field); // debug, returned: string(4) "#ccc" 

    Have a nice day! =D