Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- add_action('init', 'wlg_cstm_register');
- function wlg_cstm_register() {
- $product_labels = array(
- 'name' => _x('Products', 'post type general name'),
- 'singular_name' => _x('product', 'post type singular name'),
- 'add_new' => _x('Add New', 'product'),
- 'add_new_item' => __('Add New Products'),
- 'edit_item' => __('Edit Products'),
- 'new_item' => __('New product'),
- 'view_item' => __('View Products'),
- 'search_items' => __('Search Products'),
- 'not_found' => __('No Products found'),
- 'not_found_in_trash' => __('No Products found in Trash'),
- 'parent_item_colon' => ''
- );
- $product_args = array(
- 'labels' => $product_labels,
- 'public' => true,
- 'show_ui' => true,
- 'capability_type' => 'post',
- 'hierarchical' => false,
- 'rewrite' => true,
- 'supports' => array('title', 'editor', 'thumbnail'),
- 'taxonomies' => array( '' ),
- 'menu_icon' => get_bloginfo('template_directory') . '/images/products-icon.png', // Icon Path
- 'has_archive' => true
- );
- register_post_type( 'product' , $product_args );
- register_taxonomy( 'brands', 'product', array( 'hierarchical' => true, 'label' => __('Product Brands'), 'query_var' => 'brands' ) );
- }
- add_action("admin_init", "admin_init");
- add_action('save_post', 'save_points', 1, 2);
- function admin_init(){
- add_meta_box("productInfo-meta", "Product Details", "product_meta_options", 'product', "normal", "low");
- }
- function product_meta_options(){
- global $post;
- $custom = get_post_custom($post->ID);
- $category = (!empty($custom["_category"][0])) ? $custom["_category"][0] : '';
- $brand = (!empty($custom["_brand"][0])) ? $custom["_brand"][0] : '';
- $features = (!empty($custom["_features"][0])) ? $custom["_features"][0] : '';
- $holds = (!empty($custom["_holds"][0])) ? $custom["_holds"][0] : '';
- $content = (!empty($custom["_custom_content"][0])) ? $custom["_custom_content"][0] : '';
- ?>
- <table>
- <tr>
- <td>Category
- <td> <input type="text" size="100" name="category" value="<?php echo $category; ?>" /> </td>
- </tr>
- <tr>
- <td>Brand
- <td> <input type="text" size="100" name="brand" value="<?php echo $brand; ?>" /> </td>
- </tr>
- <tr>
- <td>Features</td>
- <td><?php wp_editor( $features, 'features', $settings = array('textarea_rows'=>20) ); ?></td>
- </tr>
- <tr>
- <td>Content</td>
- <td>
- <?php wp_editor( $content, 'custom_content', $settings = array('textarea_rows'=>20) );?>
- </td>
- </tr>
- <tr>
- <td>Holds</td>
- <td><?php wp_editor( $holds, 'holds', $settings = array('textarea_rows'=>20) ); ?></td>
- </tr>
- </table>
- <?php
- }
- function save_points($postid,$post){
- global $_POST;
- // set the ID to the parent post, not the revision
- $postid = (wp_is_post_revision( $postid )) ? wp_is_post_revision( $post ) : $postid;
- $post_type = get_post_type( $postid );
- if ('product' == $post_type) {
- update_post_meta($postid, "_category", $_POST["category"]);
- update_post_meta($postid, "_brand", $_POST["brand"]);
- update_post_meta($postid, "_features", $_POST["features"]);
- update_post_meta($postid, "_holds", $_POST["holds"]);
- update_post_meta($postid, "_custom_content", $_POST["custom_content"]); // save the data
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement