Support

Account

Home Forums General Issues Outputting checkboxes as unordered list Reply To: Outputting checkboxes as unordered list

  • 
    $site_features = get_field('site_features');
    if( $site_features ): ?>
    <ul>
        <?php 
    // notice the missing "s"
    foreach( $site_features as $site_feature ): ?>
            <li><?php echo $site_feature; ?></li>
        <?php endforeach; ?>
    </ul>
    <?php endif; ?>
    

    What does this do?

    
    foreach( $site_features as $site_features ):
    

    The first iteration of this loop sets $site_features (an array) to the string of whatever is in the first array value. This is the same as doing

    
    $site_features = $site_features[0]
    

    and this breaks your loop. Lets say that the first value of that array is “Some String”, then the next itteration will set $site_features equal to the second character of the string.