如果选中了 Wordpress,请选中自定义元复选框

Check custom meta checkbox if it's checked Wordpress

    // 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"]);
}

我需要在 post 页面上添加自定义元复选框以启用某些内容。上面的代码来自另一个 Whosebug 答案。当我点击更新 post 时,它确实保存了校验值,但我不明白如何测试它是否在我要显示内容的页面上被选中。

if (isset()) 测试是否有值,所以它总是返回 true,即使它没有被检查。有什么方法可以测试 checked="checked" 值吗?如果我检查元素,这就是正在更新的内容。

检查

if($field_id_value == "on") $field_id_checked = 'checked="checked"';