Advertisement
cirossmonteiro

custom_type_field

Aug 28th, 2018
129
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.26 KB | None | 0 0
  1. <?php
  2.  
  3. //above here it's theme's code
  4.  
  5. add_action('init', 'coupon_register');
  6.  
  7. function coupon_register() {
  8.  
  9.     $labels = array(
  10.         'name' => _x('Coupons', 'post type general name'),
  11.         'singular_name' => _x('Coupon', 'post type singular name'),
  12.         'add_new' => _x('Add New', 'coupon item'),
  13.         'add_new_item' => __('Add New Coupon Item'),
  14.         'edit_item' => __('Edit Coupon Item'),
  15.         'new_item' => __('New Coupon Item'),
  16.         'view_item' => __('View Coupon Item'),
  17.         'search_items' => __('Search Coupon'),
  18.         'not_found' =>  __('Nothing found'),
  19.         'not_found_in_trash' => __('Nothing found in Trash'),
  20.         'parent_item_colon' => ''
  21.     );
  22.  
  23.     $args = array(
  24.         'labels' => $labels,
  25.         'public' => true,
  26.         'publicly_queryable' => true,
  27.         'show_ui' => true,
  28.         'query_var' => true,
  29.         'menu_icon' => get_stylesheet_directory_uri() . '/cuponeria.png',
  30.         'rewrite' => true,
  31.         'capability_type' => 'post',
  32.         'hierarchical' => false,
  33.         'menu_position' => null,
  34.         'supports' => array('title','editor','thumbnail')
  35.       );
  36.  
  37.     register_post_type( 'coupon' , $args );
  38.     flush_rewrite_rules();
  39. }
  40.  
  41. register_taxonomy("coupon_category", array("coupon"), array("hierarchical" => true, "label" => "Coupon_categories", "singular_label" => "Coupon_category", "rewrite" => true));
  42. register_taxonomy("stores", array("coupon"), array("hierarchical" => true, "label" => "Stores", "singular_label" => "Store", "rewrite" => true));
  43.  
  44. add_action("admin_init", "admin_init");
  45.  
  46. function admin_init(){
  47.   add_meta_box("basic_info", "Basic info about coupon", "basic_info", "coupon", "normal", "low");
  48. }
  49.  
  50. function basic_info() {
  51.   global $post;
  52.   $custom = get_post_custom($post->ID);
  53.   $discount_percentage = $custom["discount_percentage"][0];
  54.   $expire_date = $custom["expire_date"][0];
  55.   ?>
  56.   <p><label>Discount percentage: </label><br />
  57.   <input cols="50" name="discount_percentage" value = "<?php echo $discount_percentage; ?>"></p>
  58.   <p><label>Expire at: </label><br />
  59.   <input cols="50" name="expire_date" value = "<?php echo $expire_date; ?>"></p>
  60.   <?php
  61. }
  62.  
  63. add_action('save_post', 'save_details');
  64.  
  65. function save_details(){
  66.   global $post;
  67.   update_post_meta($post->ID, "discount_percentage", $_POST["discount_percentage"]);
  68.   update_post_meta($post->ID, "expire_date", $_POST["expire_date"]);
  69. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement