Reusable-Custom-WordPress-Meta-Boxes icon indicating copy to clipboard operation
Reusable-Custom-WordPress-Meta-Boxes copied to clipboard

Single Checkbox Won't Uncheck

Open INVSBL-HND opened this issue 12 years ago • 1 comments

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;

Screen Shot 2013-02-13 at 11 40 27 AM

INVSBL-HND avatar Feb 13 '13 16:02 INVSBL-HND

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

LinzardMac avatar Feb 12 '15 01:02 LinzardMac