Advertisement
Guest User

WordPress Matabox

a guest
Sep 22nd, 2011
235
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.14 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_details");
  34.  
  35. // WP meta box attributes
  36.  
  37. function save_details( $post_ID ) {
  38.     if( isset($_POST) ) {
  39.         update_post_meta( $post_ID, 'price', $_POST['price'] );
  40.     }
  41. }
  42.  
  43. // WP Hook to execute meta box action
  44. if (is_admin())
  45.     add_action('admin_menu', 'create_my_meta_box');
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement