Data in custom meta box not saved
-
I had it working, but now it’s not working any more.
I’ve added some custom metaboxes to my edit post page and I have the following problems:
1. Meta data not stored (was working)
2. Medta not deleted when empty (was not working wen 1. was working).Is there something wrong with my code?
I got the following code in my functions.php file:
add_action( 'admin_menu', 'create_custom_meta_box' ); add_action( 'save_post', 'save_custom_post_meta_box', 10, 2 ); function create_custom_meta_box() { add_meta_box( 'Intro', __('Intro'), 'post_intro_meta_box', 'post', 'normal', 'high' ); } function save_custom_post_meta_box( $post_id, $post ) { if ( !current_user_can( 'edit_post', $post_id ) ) return $post_id; // Custom intro text box (Ingress) // If custom field does not exists, it is created. // Then add, update and delete handles are added /*--------------------------------------------------------------------------- */ if ( !wp_verify_nonce( $_POST['post_intro_meta_box_nonce'], plugin_basename( __FILE__ ) ) ) return $post_id; // Mini intro $meta_value = get_post_meta( $post_id, '_post_mini_intro', true ); $new_meta_value = stripslashes( $_POST['post_mini_intro'] ); if ( $new_meta_value && '' == $meta_value ) add_post_meta( $post_id, '_post_mini_intro', $new_meta_value, true ); elseif ( $new_meta_value != $meta_value ) update_post_meta( $post_id, '_post_mini_intro', $new_meta_value ); elseif ( '' == $new_meta_value && $meta_value ) delete_post_meta( $post_id, '_post_mini_intro', $meta_value ); }
Viewing 2 replies - 1 through 2 (of 2 total)
Viewing 2 replies - 1 through 2 (of 2 total)
- The topic ‘Data in custom meta box not saved’ is closed to new replies.