我试图用一个复选框设置一个meta\\u框,一切正常,但是如果我取消选中并保存帖子,它会再次标记为选中,我一直在查看,但我找不到我的错误。
看看我的代码。
function am_checkbox_option() {
global $post;
$custom = get_post_custom($post->ID);
$front_event = $custom["front_event"][0];
wp_nonce_field(__FILE__, \'am_front_event\');
if ( $front_event ) {
$checked = "checked=\\"checked\\"";
} else {
$checked = "";
}
?>
<label>Display Content? (type yes):</label>
<input type="checkbox" name="front_event" value="true" <?php echo $checked; ?> />
<?php
}
}
add_action(\'save_post\', function() {
if ( defined( \'DOING_AUTOSAVE\') && DOING_AUTOSAVE ) return;
global $post;
if ( $_POST && !wp_verify_nonce($_POST[\'am_front_event\'], __FILE__) ) {
return;
}
if ( isset($_POST[\'front_event\']) ) {
update_post_meta($post->ID, \'front_event\', $_POST[\'front_event\']);
}
});
提前感谢