1 comment

  1. You should use delete_post_meta( $post->ID, 'show_links' ); instead of delete_post_meta( $post->ID, 'show_links', 1 ); the last form is used to delete specific values when you have multiple values with the same key. Here you most probably already stored a value which is an empty string that you never deleted and that’s what you get when you call get_post_meta. So this should solve your problem:

    if ( isset( $_POST['show_links'] ) && $_POST['show_links'] == 1) {
        update_post_meta( $post->ID, 'show_links', 1 ); 
    } else {
        delete_post_meta( $post->ID, 'show_links' ); 
    }
    

    However, the way you do it kind of forces the system to never remember the user chose not to “show links” and they will have to uncheck the box each time they change the post (which is different than “by default it’s on”)

Comments are closed.