I’ve got a frontend form with text, select and checkbox inputs the text and selects update and work just fine, using update_post_meta() however the checkboxes aren’t updating. Since they’re stored in a serialized array do I need to use a different function or just set it up differently?
I can’t use the acf_form() function as the entire form is a mix of CMB2 custom fields and ACF fields.
update_post_meta($post_id, ‘appliances’, esc_attr(strip_tags($_POST[‘customMetaAppliances[]’])));
(I’ve tried update_field() as well, the same result)
Here’s the code to output the checkboxes on the frontend as well, which is working perfectly, its just that the checked options aren’t saving to the database.
<?php
$allCheckbox = get_field('appliances'); //Checked value from backend
$field_key = "field_5a0a1264370c0"; //Get value using key
$post_id = get_the_ID();
$field = get_field_object($field_key, $post_id);
$count = 0;
foreach($field['choices'] as $lab => $val){
if(is_array($allCheckbox) && in_array($val, $allCheckbox)){
$checked = 'checked = "checked"';
//$enable = '';
} else {
$checked = '';
//$enable = 'disabled=""';
}
?>
<li><input type="checkbox" name="customMetaAppliances[]" id="customMetaAppliances" value="<?php echo $lab; ?>" <?php echo $checked; ?> />
<label><?php echo $val; ?></label></li>
<?php
$count++;
if ($count == 3) {
echo '</ul><ul class="propfeatures col span_6">';
$count = 0;
}
} ?>
When viewing the row within the database this is whats being passed, so the array of checkboxes is being ignored?