I am attempting to give a checkbox into my custom meta box in WordPress and that i went into an issue with saving it - whenever I look into the checkbox increase the publish/page, it returns unchecked again.

Here's the code I am using:

    'sl-meta-box-sidebar',      // id
    'Sidebar On/Off',           // title
    'sl_meta_box_sidebar',      // callback function
    'page',                     // type of write screen
    'side',                     // context
    'low'                       // priority

function sl_meta_box_sidebar() {
    global $meta; sl_post_meta( $post->ID ); ?>
    <input type="checkbox" name="sl_meta[sidebar]" value="<?php echo htmlspecialchars ($meta['sidebar']); ?>" />Check to turn the sidebar <strong>off</strong> on this page.

This produces the checkbox within the sidebar from the "Edit Page" screen, because it should, not a problem there. I am unsure what must i type in the worth of the checkbox, with text fields it clearly returns whatever was saved as meta information... I attempted simply using "checked" rather cause that might be my first guess (then simply just look for the worthiness when utilizing this meta data), however it did not save the checkbox either.

Here's the function that saves all of the meta data, that we assume causes this issue:

function sl_save_meta_box( $post_id, $post ) {
    global $post, $type;

    $post = get_post( $post_id );

    if( !isset( $_POST[ "sl_meta" ] ) )

    if( $post->post_type == 'revision' )

    if( !current_user_can( 'edit_post', $post_id ))

    $meta = apply_filters( 'sl_post_meta', $_POST[ "sl_meta" ] );

    foreach( $meta as $key => $meta_box ) {
        $key = 'meta_' . $key;
        $curdata = $meta_box;
        $olddata = get_post_meta( $post_id, $key, true );

        if( $olddata == "" && $curdata != "" )
            add_post_meta( $post_id, $key, $curdata );
        elseif( $curdata != $olddata )
            update_post_meta( $post_id, $key, $curdata, $olddata );
        elseif( $curdata == "" )
            delete_post_meta( $post_id, $key );

    do_action( 'sl_saved_meta', $post );

add_action( 'save_post', 'sl_save_meta_box', 1, 2 );

It really works perfectly for text fields, however the checkbox just will not save. I am unsure when the saving function is wrong, or shall we be held missing something about the need for the checkbox.

Any help appreciated!

I'd challenge with this formerly here is the way i solved it.

First, creating the Checkbox.

function sl-meta-box-sidebar(){
    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 } ?>

Next, saving.

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;
} ?>