Support

Account

Home Forums Front-end Issues Checkbox trouble Reply To: Checkbox trouble

  • I was speaking more about the repeater loop and your attempt at using get_sub_field_object() so that I might see what you are doing wrong.

    This is a simple loop that will get a sub field object and output that object to the page so you can see what you’re working with.

    
    if (get_field('repeater')) {
        while (has_sub_field('repeater')) {
            echo '<pre>'; print_r(get_sub_field_object('checkbox')); echo '</pre>';
        }
    }
    

    The output of this looks something like this:

    
    Array
    (
        [ID] => 545
        [key] => field_558ef367f2c80
        [label] => checkbox
        [name] => checkbox
        [prefix] => 
        [type] => checkbox
        [value] => Array
            (
                [0] => choice1
                [1] => choice2
            )
    
        [menu_order] => 0
        [instructions] => 
        [required] => 0
        [id] => 
        [class] => 
        [conditional_logic] => 0
        [parent] => 544
        [wrapper] => Array
            (
                [width] => 
                [class] => 
                [id] => 
            )
    
        [_name] => checkbox
        [_input] => 
        [_valid] => 1
        [choices] => Array
            (
                [choice1] => Choice 1
                [choice2] => Choice 2
                [choice3] => Choice 3
                [choice4] => Choice 4
            )
    
        [default_value] => Array
            (
                [] => 
            )
    
        [layout] => vertical
        [toggle] => 0
    )
    

    There area that you’ll get your labels from is in the index [choices]. You’ll need to loop through that array and compare the values in the returned values array with the values these values to get the labels.

    Hope that helps.

    ~JH