Support

Account

Home Forums General Issues Grabbing label and value from checkbox for a list

Solved

Grabbing label and value from checkbox for a list

  • Hey All

    Been trying to solve this and you guys might know!

    I am trying to print a list of the checkboxes into a unordered list and I want to be able to style each individual list item so they all need a unique class. So I have this.

    <?php
    $field = get_field_object(‘facilities’);
    $value = get_field(‘facilities’);
    $label = $field[‘choices’][ $value ];

    echo ‘<ul class=”facts”>’;
    foreach( $value as $p ){
    echo ‘<li class=”‘.$l.'”>’.$p.’‘;
    }
    echo ‘‘;
    ?>

    This at the moment only prints the value of the check box but I need to also print the label at the same time.

    I want the value to be the class name and the label to be what is shown in the bullet list. At the moment I can only seem to get the value from the array and not the label and I can not do it all in the same loop.

    My php is not advanced so your help would be great.

  • 
    $field = get_field_object('facilities');
    echo '<ul>';
    foreach ($field['choices'] as $value => $label) {
      echo '<li>',$value,' => ',$label,'</li>';
    }
    echo '</ul>
    
Viewing 2 posts - 1 through 2 (of 2 total)

The topic ‘Grabbing label and value from checkbox for a list’ is closed to new replies.