WPAlchemy – Checkboxes not saving

After more searching I decided to try one of the alternative methods listed in the checkbox-meta.php example file. I used a “foreach” loop instead of the “while” loop and the checkbox state is now loading properly.

Here’s the updated code:

<?php foreach ($items as $i => $item): ?>

    <?php $mb->the_field('t_enabled_widgets', WPALCHEMY_FIELD_HINT_CHECKBOX_MULTI); ?>

    <input type="checkbox" name="<?php $mb->the_name(); ?>" value="<?php echo $item; ?>"<?php $mb->the_checkbox_state($item); ?>/>
    <span><?php echo ucwords(str_replace("-", " ", $item )); ?></span>

<?php endforeach; ?>