Advertisement
Guest User

Final Code

a guest
Sep 22nd, 2011
406
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.36 KB | None | 0 0
  1. // Tells WP to add a Menu section
  2. add_action( 'init', 'create_my_post_types' );
  3.  
  4. // WP Menu section attributes
  5. function create_my_post_types() {
  6.     register_post_type( 'menu',
  7.         array(
  8.             'labels' => array(
  9.                 'name' => __( 'Menus' ),
  10.                 'singular_name' => __( 'Menu' ),
  11.             ),
  12.             'public' => true,
  13.             'menu_position' => 5,
  14.             'taxonomies' => array('category'),
  15.             'supports' => array('title','editor','excerpt','thumbnail'),
  16.         )
  17.     );
  18. }
  19.  
  20. // Tells WP to add a new meta box
  21. function create_my_meta_box() {
  22.     add_meta_box("price-meta", "Item Price", "price", "menu", "side", "low");
  23. }
  24.  
  25. // Echoes the content of our meta box
  26. function price(){
  27.      global $post;
  28.      $meta = get_post_meta($post->ID, 'price', true);
  29.      echo '$ <input type="text" name="price" value="'.$meta.'" />';
  30. }
  31.  
  32. // Saves the content of our meta box
  33. add_action( 'save_post', 'save_meta_details' );
  34.  
  35. // WP meta box attributes
  36. function save_meta_details( $post_id ) {
  37.     global $post;
  38.     // Skip auto save
  39.     if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) {
  40.         return $post_id;
  41.     }
  42.     // Check for your post type
  43.     if( $post->post_type == 'menu' ) {
  44.         if( isset($_POST['price']) ) { update_post_meta( $post->ID, 'price', $_POST['price'] );}
  45.  
  46.     }
  47. }
  48.  
  49. // WP Hook to execute meta box action
  50. if (is_admin())
  51.     add_action('admin_menu', 'create_my_meta_box');
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement