Advertisement
Guest User

MY CPT

a guest
Jul 3rd, 2013
108
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 3.38 KB | None | 0 0
  1. <?php
  2. add_action('init', 'wlg_cstm_register');  
  3.    
  4.  function wlg_cstm_register() {  
  5.        
  6.     $product_labels = array(
  7.     'name' => _x('Products', 'post type general name'),
  8.     'singular_name' => _x('product', 'post type singular name'),
  9.     'add_new' => _x('Add New', 'product'),
  10.     'add_new_item' => __('Add New Products'),
  11.     'edit_item' => __('Edit Products'),
  12.     'new_item' => __('New product'),
  13.     'view_item' => __('View Products'),
  14.     'search_items' => __('Search Products'),
  15.     'not_found' =>  __('No Products found'),
  16.     'not_found_in_trash' => __('No Products found in Trash'),
  17.     'parent_item_colon' => ''
  18. );
  19.  
  20.     $product_args = array(  
  21.          'labels' => $product_labels,  
  22.          'public' => true,  
  23.          'show_ui' => true,  
  24.          'capability_type' => 'post',  
  25.          'hierarchical' => false,  
  26.          'rewrite' => true,
  27.          'supports' => array('title', 'editor', 'thumbnail'),
  28.         'taxonomies' => array( '' ),
  29.         'menu_icon' => get_bloginfo('template_directory') . '/images/products-icon.png',  // Icon Path
  30.         'has_archive' => true        
  31.         );
  32.  
  33.  
  34.      register_post_type( 'product' , $product_args );
  35.      register_taxonomy( 'brands', 'product', array( 'hierarchical' => true, 'label' => __('Product Brands'), 'query_var' => 'brands' ) );
  36.  }
  37.  
  38.  add_action("admin_init", "admin_init");
  39. add_action('save_post', 'save_points', 1, 2);
  40. function admin_init(){
  41.   add_meta_box("productInfo-meta", "Product Details", "product_meta_options", 'product', "normal", "low");
  42. }
  43.  
  44. function product_meta_options(){
  45.   global $post;
  46.   $custom = get_post_custom($post->ID);
  47.   $category = (!empty($custom["_category"][0])) ? $custom["_category"][0] : '';
  48.   $brand = (!empty($custom["_brand"][0])) ? $custom["_brand"][0]  : '';
  49.   $features = (!empty($custom["_features"][0])) ? $custom["_features"][0]  : '';
  50.   $holds = (!empty($custom["_holds"][0])) ? $custom["_holds"][0]  : '';
  51.   $content = (!empty($custom["_custom_content"][0])) ? $custom["_custom_content"][0]  : '';
  52. ?>
  53. <table>
  54.     <tr>
  55.         <td>Category
  56.         <td> <input type="text" size="100" name="category" value="<?php echo $category; ?>" /> </td>
  57.     </tr>
  58.     <tr>
  59.         <td>Brand
  60.         <td> <input type="text" size="100" name="brand" value="<?php echo $brand; ?>" /> </td>
  61.     </tr>
  62.     <tr>
  63.         <td>Features</td>
  64.         <td><?php wp_editor( $features, 'features', $settings = array('textarea_rows'=>20) ); ?></td>
  65.     </tr>
  66.     <tr>
  67.         <td>Content</td>
  68.         <td>
  69.         <?php wp_editor( $content, 'custom_content', $settings = array('textarea_rows'=>20) );?>
  70.         </td>
  71.     </tr>
  72.     <tr>
  73.         <td>Holds</td>
  74.         <td><?php wp_editor( $holds, 'holds', $settings = array('textarea_rows'=>20) ); ?></td>
  75.     </tr>
  76. </table>
  77.  
  78. <?php
  79. }
  80.  
  81. function save_points($postid,$post){
  82.   global $_POST;
  83.   // set the ID to the parent post, not the revision
  84.   $postid = (wp_is_post_revision( $postid )) ? wp_is_post_revision( $post ) : $postid;
  85.   $post_type = get_post_type( $postid );
  86.   if ('product' == $post_type) {
  87.     update_post_meta($postid, "_category", $_POST["category"]);
  88.     update_post_meta($postid, "_brand", $_POST["brand"]);
  89.     update_post_meta($postid, "_features", $_POST["features"]);
  90.     update_post_meta($postid, "_holds", $_POST["holds"]);
  91.     update_post_meta($postid, "_custom_content", $_POST["custom_content"]); // save the data
  92.   }
  93. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement