😅How to save a checkbox meta box in WordPress? namkhoa.net.vn (ok)

https://stackoverflow.com/questions/7526374/how-to-save-a-checkbox-meta-box-in-wordpress

function thachpham_meta_box()
{
 add_meta_box( 'thong-tin', 'Hiển thị thông tin bác sĩ', 'thachpham_thongtin_output', 'post' );
}
add_action( 'add_meta_boxes', 'thachpham_meta_box' );
function thachpham_thongtin_output()
{
  global $post;
  $custom = get_post_custom($post->ID);
  $sl_meta_box_sidebar = $custom["sl-meta-box-sidebar"][0]; 
  ?>
  <input type="checkbox" name="sl-meta-box-sidebar" <?php if( $sl_meta_box_sidebar == true ) { ?>checked="checked"<?php } ?> />  Check the Box.
  <?php
}
add_action('save_post', 'save_details');
function save_details($post_ID = 0) {
  $post_ID = (int) $post_ID;
  $post_type = get_post_type( $post_ID );
  $post_status = get_post_status( $post_ID );
  if ($post_type) {
  update_post_meta($post_ID, "sl-meta-box-sidebar", $_POST["sl-meta-box-sidebar"]);
  }
 return $post_ID;
} 

Last updated