WordPress custom post type and checkboxes
-
Hi! I’m trying to add a checkbox as a field in a custom post type but I can’t get WordPress to save the value of checked or unchecked. I don’t have the foggiest idea of how to make it work and I was hoping one of you guys could point me in the right direction!
Inside my function to create the checkbox I have:
$checkbox = $custom["checkbox"][0];Which works fine. And for the input field I have:
<?php if($checkbox == "true") $checkbox = 'checked="checked"';?> <input type="checkbox" id="checkbox" name="checkbox" value="<?php echo (isset($checkbox) && $checkbox != '' ? 'checked' : ''); ?>" />The if/else stuff was something I was trying out from a different forum topic. I don’t know if it should be there or not, but it doesn’t work even without it. The checkbox shows up, just doesn’t save.
Then for the update function I have:`
update_post_meta($post->ID, “checkbox”, $_POST[“checkbox”]);`Any help would be greatly appreciated!! Thanks!
The topic ‘WordPress custom post type and checkboxes’ is closed to new replies.