Custom Meta
-
Hello friends,
I am having trouble in adding Custom Meta boxes. I want to add few special meta boxes for Pages only. Here is my code and i dont know where i made the mistake but its not saving.add_action( 'add_meta_boxes', 'page_heading_box' ); function page_heading_box() { add_meta_box( 'page_heading', 'Add Page Heading', 'page_heading', 'page', 'normal', 'high' ); } function page_heading( $post ) { $values = get_post_custom( $post->ID ); $text = isset( $values['page_heading'] ); ?> <p> <label for="page_heading" class="custom_lbl_full">Page Heading</label> <input type="text" class="widefat custom_input" name="page_heading" id="page_heading" value="<?php echo $text; ?>" /> </p> <?php } add_action( 'save_post', 'cd_meta_box_save' ); function cd_meta_box_save( $post_id ) { if( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) return; if( !isset( $_POST['meta_box_nonce'] ) || !wp_verify_nonce( $_POST['meta_box_nonce'], 'my_meta_box_nonce' ) ) return; if( !current_user_can( 'edit_post' ) ) return; // Make sure your data is set before trying to save it if( isset( $_POST['page_heading'] ) ) update_post_meta( $post_id, 'page_heading', wp_kses( $_POST['page_heading'] ) ); }
Viewing 2 replies - 1 through 2 (of 2 total)
Viewing 2 replies - 1 through 2 (of 2 total)
- The topic ‘Custom Meta’ is closed to new replies.