Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function tp_meta_box_register() {
- add_meta_box( 'tp-recipe-metabox', 'Recipe Settings', 'tp_meta_box_fields', 'recipes', 'normal', 'high', null );
- }
- add_action( 'add_meta_boxes', 'tp_meta_box_register' );
- function tp_meta_box_fields( $post ){
- wp_nonce_field( basename( __FILE__ ), 'tp-metabox-nonce' );
- ?>
- <div>
- <label for="calories">Calories: </label>
- <input type="text" id="calories" name="calories" value="<?php echo get_post_meta( $post->ID, 'calories', true ); ?>">
- <br>
- </div>
- <?php
- }
- //Save Metabox data
- function tp_save_metabox( $post_id ) {
- if ( ! isset( $_POST['tp-metabox-nonce']) || ! wp_verify_nonce( $_POST['tp-metabox-nonce'], basename( __FILE__ ) ) )
- return $post_id;
- if( ! current_user_can( 'edit_post', $post_id ))
- return $post_id;
- if( defined( "DOING_AUTOSAVE") && DOING_AUTOSAVE )
- return $post_id;
- if ( isset( $_POST['calories'] ) ) {
- update_post_meta( $post_id, 'calories', sanitize_text_field( $_POST['calories'] ) );
- }
- }
- add_action( 'save_post', 'tp_save_metabox' );
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement