Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Tells WP to add a Menu section
- add_action( 'init', 'create_my_post_types' );
- // WP Menu section attributes
- function create_my_post_types() {
- register_post_type( 'menu',
- array(
- 'labels' => array(
- 'name' => __( 'Menus' ),
- 'singular_name' => __( 'Menu' ),
- ),
- 'public' => true,
- 'menu_position' => 5,
- 'taxonomies' => array('category'),
- 'supports' => array('title','editor','excerpt','thumbnail'),
- )
- );
- }
- // Tells WP to add a new meta box
- function create_my_meta_box() {
- add_meta_box("price-meta", "Item Price", "price", "menu", "side", "low");
- }
- // Echoes the content of our meta box
- function price(){
- global $post;
- $meta = get_post_meta($post->ID, 'price', true);
- echo '$ <input type="text" name="price" value="'.$meta.'" />';
- }
- // Saves the content of our meta box
- add_action( 'save_post', 'save_meta_details' );
- // WP meta box attributes
- function save_meta_details( $post_id ) {
- global $post;
- // Skip auto save
- if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) {
- return $post_id;
- }
- // Check for your post type
- if( $post->post_type == 'menu' ) {
- if( isset($_POST['price']) ) { update_post_meta( $post->ID, 'price', $_POST['price'] );}
- }
- }
- // WP Hook to execute meta box action
- if (is_admin())
- add_action('admin_menu', 'create_my_meta_box');
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement