Reusable-Custom-WordPress-Meta-Boxes
Reusable-Custom-WordPress-Meta-Boxes copied to clipboard
Single Checkbox Won't Uncheck
Single checkbox meta fields won't "uncheck" and simply revert to the "checked" state upon saving the post.
I've rewritten the checkbox case to conditionally create a hidden input type with the same name as the checkbox input to allow for successful checking, unchecking, and rechecking of single checkboxes.
Below is my suggestion for replacing lines 62-66 of meta_box.php
// checkbox
case 'checkbox':
echo '<input type="checkbox" name="' . esc_attr( $name ) . '" id="' . esc_attr( $id ) . '" ' . ($meta ? 'checked="checked"/><input type="hidden" name="' . esc_attr( $id ) . '"' : '').'/
<label for="' . esc_attr( $id ) . '">' . $desc . '</label>';
break;
I'e tried this method of fixing the error but it does not seem to work. I adjusted your variables to match my own and the HTML output is as expected but I stil get the undefined index and "headers already sent" errors