Wordpress - Metabox with checkbox is not updating
Here is code I have used before - the main difference looks to me that you are checking if the meta exists rather than what it's value is to determine if it should be checked.
// Checkbox Meta
add_action("admin_init", "checkbox_init");
function checkbox_init(){
add_meta_box("checkbox", "Checkbox", "checkbox", "post", "normal", "high");
}
function checkbox(){
global $post;
$custom = get_post_custom($post->ID);
$field_id = $custom["field_id"][0];
?>
<label>Check for yes</label>
<?php $field_id_value = get_post_meta($post->ID, 'field_id', true);
if($field_id_value == "yes") $field_id_checked = 'checked="checked"'; ?>
<input type="checkbox" name="field_id" value="yes" <?php echo $field_id_checked; ?> />
<?php
}
// Save Meta Details
add_action('save_post', 'save_details');
function save_details(){
global $post;
if (defined('DOING_AUTOSAVE') && DOING_AUTOSAVE) {
return $post->ID;
}
update_post_meta($post->ID, "field_id", $_POST["field_id"]);
}
simple add an else clause to delete the post meta if not checked and your code will do just fine, so change :
if ( isset($_POST['front_event']) ) {
update_post_meta($post->ID, 'front_event', $_POST['front_event']);
}
to
if ( isset($_POST['front_event']) ) {
update_post_meta($post->ID, 'front_event', $_POST['front_event']);
}else{
delete_post_meta($post->ID, 'front_event');
}