Support

Account

Home Forums General Issues Get 'value' and 'label' with checkbox field

Unread

Get 'value' and 'label' with checkbox field

  • Hi, I’ve a checkbox field with options like:

    red_color : Red
    blue_color : Blue
    ...

    I need to print both the value (‘red_color’) and the label (‘Red’). I’ve tried this code from the documentation but it doesn’t work:

    <?php
    $field = get_field_object('color'); 
    $colors = get_field('color'); 
    foreach($colors as $color){
        echo "<br>Selected color: ". $color. " with label: " . $field['choices'][ $color ];
    }
    ?>

    The output is:

    selected color: Red with label: 
    selected color: Blue with label:

    How can solve it?
    Thanks

Viewing 1 post (of 1 total)

The topic ‘Get 'value' and 'label' with checkbox field’ is closed to new replies.