SHARE
TWEET

Untitled

a guest Jun 27th, 2019 65 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <?php /** Create Vehicle Listings Custom Post Type **/
  2.      
  3. if  ( 'listings' == $screen->post_type ) {
  4.       $title = 'Model name';
  5.  }
  6.  
  7.  return $title;
  8.      
  9. <?php // Add the Car Details Meta Boxes
  10.      
  11. // Style Forms
  12. echo '<style type="text/css">
  13.             .admin-col {
  14.                 display: inline-block;
  15.                 padding: 0 1rem 0 0;
  16.             }
  17.  
  18.             .col25 {
  19.                 width: 22%;
  20.             }
  21.  
  22.             @media screen and (max-width: 39.9375em) {
  23.                 .col25 {
  24.                     width: 100%;
  25.                 }
  26.             }
  27.  
  28.             .col33 {
  29.                 width: 31%;
  30.                 @media screen and (max-width: 39.9375em) {
  31.                     width: 100%;
  32.                 }
  33.             }
  34.  
  35.             .p-heading {
  36.                 font-weight: 400;
  37.             }
  38.  
  39.             .meta_fields input[type="text"], .meta_fields select {
  40.                 margin-bottom: 1rem;
  41.                 height: 3rem;
  42.             }
  43.         </style>';
  44.  
  45. // Noncename needed to verify where the data originated
  46. echo '<input type="hidden" name="details_meta_noncename" id="eventmeta_noncename" value="' .
  47. wp_create_nonce( plugin_basename(__FILE__) ) . '" />';
  48.  
  49.  
  50.  
  51. // SETUP TAXONOMY LISTS IN DROPDOWN SELECT MENU FOR MODEL YEAR AND MAKE
  52.  
  53. ////// Model Years
  54. //Get taxonomy and terms
  55. $taxonomy = 'model_year';
  56.  
  57. //Set up the taxonomy object and get terms
  58. $tax = get_taxonomy($taxonomy);
  59. $terms = get_terms($taxonomy,array('hide_empty' => 0, 'orderby' => 'name', 'order' => 'DESC'));
  60.  
  61. //Name of the form
  62. $name = 'tax_input[' . $taxonomy . ']';
  63.  
  64. //Get current and popular terms
  65. $popular = get_terms( $taxonomy, array( 'orderby' => 'count', 'order' => 'DESC', 'number' => 10, 'hierarchical' => false ) );
  66. $postterms = get_the_terms( $post->ID,$taxonomy );
  67. $current = ($postterms ? array_pop($postterms) : false);
  68. $current = ($current ? $current->term_id : 0);
  69.  
  70.  
  71. ////// Makes
  72. //Get taxonomy and terms
  73. $taxonomy_make = 'makes';
  74.  
  75. //Set up the taxonomy object and get terms
  76. $tax_m = get_taxonomy($taxonomy_make);
  77. $terms_m = get_terms($taxonomy_make,array('hide_empty' => 0, 'orderby' => 'name', 'order' => 'ASC'));
  78.  
  79. //Name of the form
  80. $name_m = 'tax_input[' . $taxonomy_make . ']';
  81.  
  82. //Get current and popular terms
  83. $popular_m = get_terms( $taxonomy_make, array( 'orderby' => 'count', 'order' => 'DESC', 'number' => 10, 'hierarchical' => false ) );
  84. $postterms_m = get_the_terms( $post->ID,$taxonomy_make );
  85. $current_m = ($postterms_m ? array_pop($postterms_m) : false);
  86. $current_m = ($current_m ? $current_m->term_id : 0);
  87.  
  88. ////// Body Types
  89. //Get taxonomy and terms
  90. $taxonomy_body_type = 'body_type';
  91.  
  92. //Set up the taxonomy object and get terms
  93. $tax_body_type = get_taxonomy($taxonomy_body_type);
  94. $terms_body_type = get_terms($taxonomy_body_type,array('hide_empty' => 0, 'orderby' => 'name', 'order' => 'ASC'));
  95.  
  96. //Name of the form
  97. $name_body_type = 'tax_input[' . $taxonomy_body_type . ']';
  98.  
  99. //Get current and popular terms
  100. $popular_body_type = get_terms( $taxonomy_body_type, array( 'orderby' => 'count', 'order' => 'DESC', 'number' => 10, 'hierarchical' => false ) );
  101. $postterms_body_type = get_the_terms( $post->ID,$taxonomy_body_type );
  102. $current_body_type = ($postterms_body_type ? array_pop($postterms_body_type) : false);
  103. $current_body_type = ($current_body_type ? $current_body_type->term_id : 0);
  104.  
  105. ////// Colors
  106. //Get taxonomy and terms
  107. $taxonomy_colors = 'colors';
  108.  
  109. //Set up the taxonomy object and get terms
  110. $tax_colors = get_taxonomy($taxonomy_colors);
  111. $terms_colors = get_terms($taxonomy_colors,array('hide_empty' => 0, 'orderby' => 'name', 'order' => 'ASC'));
  112.  
  113. //Name of the form
  114. $name_colors = 'tax_input[' . $taxonomy_colors . ']';
  115.  
  116. //Get current and popular terms
  117. $popular_colors = get_terms( $taxonomy_colors, array( 'orderby' => 'count', 'order' => 'DESC', 'number' => 10, 'hierarchical' => false ) );
  118. $postterms_colors = get_the_terms( $post->ID,$taxonomy_colors );
  119. $current_colors = ($postterms_colors ? array_pop($postterms_colors) : false);
  120. $current_colors = ($current_colors ? $current_colors->term_id : 0);
  121.  
  122.  
  123. ////// Drivetrain
  124. //Get taxonomy and terms
  125. $taxonomy_drivetrain = 'drivetrain';
  126.  
  127. //Set up the taxonomy object and get terms
  128. $tax_drivetrain = get_taxonomy($taxonomy_drivetrain);
  129. $terms_drivetrain = get_terms($taxonomy_drivetrain,array('hide_empty' => 0, 'orderby' => 'name', 'order' => 'ASC'));
  130.  
  131. //Name of the form
  132. $name_drivetrain = 'tax_input[' . $taxonomy_drivetrain . ']';
  133.  
  134. //Get current and popular terms
  135. $popular_drivetrain = get_terms( $taxonomy_drivetrain, array( 'orderby' => 'count', 'order' => 'DESC', 'number' => 10, 'hierarchical' => false ) );
  136. $postterms_drivetrain = get_the_terms( $post->ID,$taxonomy_drivetrain );
  137. $current_drivetrain = ($postterms_drivetrain ? array_pop($postterms_drivetrain) : false);
  138. $current_drivetrain = ($current_drivetrain ? $current_drivetrain->term_id : 0);
  139.  
  140.  
  141. ////// Transmissions
  142. //Get taxonomy and terms
  143. $taxonomy_transmissions = 'transmissions';
  144.  
  145. //Set up the taxonomy object and get terms
  146. $tax_transmissions = get_taxonomy($taxonomy_transmissions);
  147. $terms_transmissions = get_terms($taxonomy_transmissions,array('hide_empty' => 0, 'orderby' => 'name', 'order' => 'ASC'));
  148.  
  149. //Name of the form
  150. $name_transmissions = 'tax_input[' . $taxonomy_transmissions . ']';
  151.  
  152. //Get current and popular terms
  153. $popular_transmissions = get_terms( $taxonomy_transmissions, array( 'orderby' => 'count', 'order' => 'DESC', 'number' => 10, 'hierarchical' => false ) );
  154. $postterms_transmissions = get_the_terms( $post->ID,$taxonomy_transmissions );
  155. $current_transmissions = ($postterms_transmissions ? array_pop($postterms_transmissions) : false);
  156. $current_transmissions = ($current_transmissions ? $current_transmissions->term_id : 0);
  157.  
  158.  
  159. ////// Fuel Type
  160. //Get taxonomy and terms
  161. $taxonomy_fuel_type = 'fuel-type';
  162.  
  163. //Set up the taxonomy object and get terms
  164. $tax_fuel_type = get_taxonomy($taxonomy_fuel_type);
  165. $terms_fuel_type = get_terms($taxonomy_fuel_type,array('hide_empty' => 0, 'orderby' => 'name', 'order' => 'ASC'));
  166.  
  167. //Name of the form
  168. $name_fuel_type = 'tax_input[' . $taxonomy_fuel_type . ']';
  169.  
  170. //Get current and popular terms
  171. $popular_fuel_type = get_terms( $taxonomy_fuel_type, array( 'orderby' => 'count', 'order' => 'DESC', 'number' => 10, 'hierarchical' => false ) );
  172. $postterms_fuel_type = get_the_terms( $post->ID,$taxonomy_fuel_type );
  173. $current_fuel_type = ($postterms_fuel_type ? array_pop($postterms_fuel_type) : false);
  174. $current_fuel_type = ($current_fuel_type ? $current_fuel_type->term_id : 0);
  175.  
  176.  
  177.  
  178. ////// Engine
  179. //Get taxonomy and terms
  180. $taxonomy_engine = 'engine';
  181.  
  182. //Set up the taxonomy object and get terms
  183. $tax_engine = get_taxonomy($taxonomy_engine);
  184. $terms_engine = get_terms($taxonomy_engine,array('hide_empty' => 0, 'orderby' => 'name', 'order' => 'ASC'));
  185.  
  186. //Name of the form
  187. $name_engine = 'tax_input[' . $taxonomy_engine . ']';
  188.  
  189. //Get current and popular terms
  190. $popular_engine = get_terms( $taxonomy_engine, array( 'orderby' => 'count', 'order' => 'DESC', 'number' => 10, 'hierarchical' => false ) );
  191. $postterms_engine = get_the_terms( $post->ID,$taxonomy_engine );
  192. $current_engine = ($postterms_engine ? array_pop($postterms_engine) : false);
  193. $current_engine = ($current_engine ? $current_engine->term_id : 0);
  194.  
  195.  
  196.  
  197.  
  198.  
  199. // Get the details data if its already been entered
  200. //$year = get_post_meta($post->ID, '_price', true);
  201. $price = get_post_meta($post->ID, '_price', true);
  202. $trim = get_post_meta($post->ID, '_trim', true);
  203. $mileage = get_post_meta($post->ID, '_mileage', true);
  204. $vin_num = get_post_meta($post->ID, '_vin', true);
  205. $tot = get_post_meta($post->ID, '_tot', true);
  206. $nod = get_post_meta($post->ID, '_nod', true);
  207. $drivet = get_post_meta($post->ID, '_drivet', true);
  208. $intcol = get_post_meta($post->ID, '_intcol', true);
  209. $engine = get_post_meta($post->ID, '_engine', true);
  210.  
  211.  
  212. // Echo out the field
  213. echo '<div class="meta_fields">';
  214. echo '<div class="row">';
  215. echo '<div class="admin-col col25"><p class="p-heading">Make</p>'; ?>
  216. <select id="<?php echo $taxonomy_make; ?>checklist" name="tax_input[makes]" class="form-no-clear" style="width: 100%;
  217.      
  218. <select id="<?php echo $taxonomy; ?>checklist" name="tax_input[model_year]" class="form-no-clear" style="width: 100%;
  219.      
  220. <?php
  221. echo '</div>';
  222. echo '<div class="admin-col col25"><p class="p-heading">Body Type</p>'; ?>
  223.  
  224. <select id="<?php echo $taxonomy_body_type; ?>checklist" name="tax_input[body_type]" class="form-no-clear" style="width: 100%;
  225.      
  226. <?php
  227. echo '</div>';
  228. echo '<div class="admin-col col25"><p class="p-heading">Color</p>'; ?>
  229.  
  230. <select id="<?php echo $taxonomy_colors; ?>checklist" name="tax_input[colors]" class="form-no-clear" style="width: 100%;
  231.      
  232. <?php
  233. echo '</div>';
  234. echo '</div>';
  235. echo '<div class="row">';
  236. echo '<div class="admin-col col25"><p class="p-heading">Drivetrain</p>'; ?>
  237.  
  238. <select id="<?php echo $taxonomy_drivetrain; ?>checklist" name="tax_input[drivetrain]" class="form-no-clear" style="width: 100%;
  239.      
  240. <?php
  241. echo '</div>';
  242. echo '<div class="admin-col col25"><p class="p-heading">Transmissions</p>'; ?>
  243.  
  244. <select id="<?php echo $taxonomy_transmissions; ?>checklist" name="tax_input[transmissions]" class="form-no-clear" style="width: 100%;
  245.      
  246. <?php
  247. echo '</div>';
  248. echo '<div class="admin-col col25"><p class="p-heading">Fuel Type</p>'; ?>
  249.  
  250. <select id="<?php echo $taxonomy_fuel_type; ?>checklist" name="tax_input[fuel-type]" class="form-no-clear" style="width: 100%;
  251.      
  252. <?php
  253. echo '</div>';
  254. echo '<div class="admin-col col25"><p class="p-heading">Engine</p>'; ?>
  255.  
  256. <select id="<?php echo $taxonomy_engine; ?>checklist" name="tax_input[engine]" class="form-no-clear" style="width: 100%;
  257.      
  258. <?php
  259. echo '</div>';
  260. echo '</div>';
  261. echo '<div class="row">';
  262. echo '<div class="admin-col col25"><p class="p-heading">Vin #</p>';
  263. echo '<input type="text" name="_vin" value="' . $vin_num  . '" class="widefat" /></div>';
  264. echo '<div class="admin-col col25"><p class="p-heading">Mileage</p>';
  265. echo '<input type="text" name="_mileage" value="' . $mileage  . '" class="widefat" /></div>';
  266. echo '<div class="admin-col col25"><p class="p-heading">Interior Color</p>';
  267. echo '<input type="text" name="_intcol" value="' . $intcol  . '" class="widefat" /></div>';
  268. echo '<div class="admin-col col25"><p class="p-heading">Type of Title</p>';
  269. echo '<input type="text" name="_tot" value="' . $tot  . '" class="widefat" /></div>';
  270. echo '</div>';
  271. echo '<div class="row">';
  272. echo '<div class="admin-col col25"><p class="p-heading">Number of Doors</p>';
  273. echo '<input type="text" name="_nod" value="' . $nod  . '" class="widefat" /></div>';
  274. echo '<div class="admin-col col25"><p class="p-heading">Trim</p>';
  275. echo '<input type="text" name="_trim" value="' . $trim  . '" class="widefat" /></div>';
  276. echo '<div class="admin-col col25"><p class="p-heading">Price</p>';
  277. echo '<input type="text" name="_price" value="' . $price  . '" class="widefat" /></div>';
  278. echo '</div>';
  279. echo '</div>';
  280.      
  281. // verify this came from the our screen and with proper authorization,
  282. // because save_post can be triggered at other times
  283. if ( !wp_verify_nonce( $_POST['details_meta_noncename'], plugin_basename(__FILE__) )) {
  284. return $post->ID;
  285. }
  286.  
  287. // Is the user allowed to edit the post or page?
  288. if ( !current_user_can( 'edit_post', $post->ID ))
  289.     return $post->ID;
  290.  
  291. // OK, we're authenticated: we need to find and save the data
  292. // We'll put it into an array to make it easier to loop though.
  293.  
  294. //$year_meta['_myear'] = $_POST['_myear'];
  295. //$makes_meta['_makes'] = $_POST['_makes'];
  296. //$body_type_meta['_body'] = $_POST['_body'];
  297. $details_meta['_price'] = $_POST['_price'];
  298. $trim_meta['_trim'] = $_POST['_trim'];
  299. $mileage_meta['_mileage'] = $_POST['_mileage'];
  300. $vin_num_meta['_vin'] = $_POST['_vin'];
  301. $tot_meta['_tot'] = $_POST['_tot'];
  302. $nod_meta['_nod'] = $_POST['_nod'];
  303. $drivet_meta['_drivet'] = $_POST['_drivet'];
  304. $intcol_meta['_intcol'] = $_POST['_intcol'];
  305. $engine_meta['_engine'] = $_POST['_engine'];
  306.  
  307. // Add values of $price_meta as custom fields
  308.  
  309. foreach ($details_meta as $key => $value) { // Cycle through the $details_meta array!
  310.     if( $post->post_type == 'revision' ) return; // Don't store custom data twice
  311.     $value = implode(',', (array)$value); // If $value is an array, make it a CSV (unlikely)
  312.     if(get_post_meta($post->ID, $key, FALSE)) { // If the custom field already has a value
  313.         update_post_meta($post->ID, $key, $value);
  314.     } else { // If the custom field doesn't have a value
  315.         add_post_meta($post->ID, $key, $value);
  316.     }
  317.     if(!$value) delete_post_meta($post->ID, $key); // Delete if blank
  318. }
  319.  
  320. foreach ($trim_meta as $key => $value) { // Cycle through the $details_meta array!
  321.     if( $post->post_type == 'revision' ) return; // Don't store custom data twice
  322.     $value = implode(',', (array)$value); // If $value is an array, make it a CSV (unlikely)
  323.     if(get_post_meta($post->ID, $key, FALSE)) { // If the custom field already has a value
  324.         update_post_meta($post->ID, $key, $value);
  325.     } else { // If the custom field doesn't have a value
  326.         add_post_meta($post->ID, $key, $value);
  327.     }
  328.     if(!$value) delete_post_meta($post->ID, $key); // Delete if blank
  329. }
  330.  
  331. foreach ($vin_num_meta as $key => $value) { // Cycle through the $details_meta array!
  332.     if( $post->post_type == 'revision' ) return; // Don't store custom data twice
  333.     $value = implode(',', (array)$value); // If $value is an array, make it a CSV (unlikely)
  334.     if(get_post_meta($post->ID, $key, FALSE)) { // If the custom field already has a value
  335.         update_post_meta($post->ID, $key, $value);
  336.     } else { // If the custom field doesn't have a value
  337.         add_post_meta($post->ID, $key, $value);
  338.     }
  339.     if(!$value) delete_post_meta($post->ID, $key); // Delete if blank
  340. }
  341.  
  342.  
  343. foreach ($makes_meta as $key => $value) { // Cycle through the $details_meta array!
  344.     if( $post->post_type == 'revision' ) return; // Don't store custom data twice
  345.     $value = implode(',', (array)$value); // If $value is an array, make it a CSV (unlikely)
  346.     if(get_term_meta($term->term_id, $key, FALSE)) { // If the custom field already has a value
  347.         update_term_meta($term->term_id, $key, $value);
  348.     } else { // If the custom field doesn't have a value
  349.         add_term_meta($term->term_id, $key, $value);
  350.     }
  351.     if(!$value) delete_term_meta($post->ID, $key); // Delete if blank
  352. }
  353.  
  354. foreach ($year_meta as $key => $value) { // Cycle through the $details_meta array!
  355.     if( $post->post_type == 'revision' ) return; // Don't store custom data twice
  356.     $value = implode(',', (array)$value); // If $value is an array, make it a CSV (unlikely)
  357.     if(get_term_meta($term->term_id, $key, FALSE)) { // If the custom field already has a value
  358.         update_term_meta($term->term_id, $key, $value);
  359.     } else { // If the custom field doesn't have a value
  360.         add_term_meta($term->term_id, $key, $value);
  361.     }
  362.     if(!$value) delete_term_meta($post->ID, $key); // Delete if blank
  363. }
  364.  
  365. /*foreach ($body_type_meta as $key => $value) { // Cycle through the $details_meta array!
  366.     if( $post->post_type == 'revision' ) return; // Don't store custom data twice
  367.     $value = implode(',', (array)$value); // If $value is an array, make it a CSV (unlikely)
  368.     if(get_term_meta($term->term_id, $key, FALSE)) { // If the custom field already has a value
  369.         update_term_meta($term->term_id, $key, $value);
  370.     } else { // If the custom field doesn't have a value
  371.         add_term_meta($term->term_id, $key, $value);
  372.     }
  373.     if(!$value) delete_term_meta($post->ID, $key); // Delete if blank
  374. }*/
  375.  
  376. foreach ($mileage_meta as $key => $value) { // Cycle through the $details_meta array!
  377.     if( $post->post_type == 'revision' ) return; // Don't store custom data twice
  378.     $value = implode(',', (array)$value); // If $value is an array, make it a CSV (unlikely)
  379.     if(get_post_meta($post->ID, $key, FALSE)) { // If the custom field already has a value
  380.         update_post_meta($post->ID, $key, $value);
  381.     } else { // If the custom field doesn't have a value
  382.         add_post_meta($post->ID, $key, $value);
  383.     }
  384.     if(!$value) delete_post_meta($post->ID, $key); // Delete if blank
  385. }
  386.  
  387. foreach ($tot_meta as $key => $value) { // Cycle through the $details_meta array!
  388.     if( $post->post_type == 'revision' ) return; // Don't store custom data twice
  389.     $value = implode(',', (array)$value); // If $value is an array, make it a CSV (unlikely)
  390.     if(get_post_meta($post->ID, $key, FALSE)) { // If the custom field already has a value
  391.         update_post_meta($post->ID, $key, $value);
  392.     } else { // If the custom field doesn't have a value
  393.         add_post_meta($post->ID, $key, $value);
  394.     }
  395.     if(!$value) delete_post_meta($post->ID, $key); // Delete if blank
  396. }
  397.  
  398. foreach ($nod_meta as $key => $value) { // Cycle through the $details_meta array!
  399.     if( $post->post_type == 'revision' ) return; // Don't store custom data twice
  400.     $value = implode(',', (array)$value); // If $value is an array, make it a CSV (unlikely)
  401.     if(get_post_meta($post->ID, $key, FALSE)) { // If the custom field already has a value
  402.         update_post_meta($post->ID, $key, $value);
  403.     } else { // If the custom field doesn't have a value
  404.         add_post_meta($post->ID, $key, $value);
  405.     }
  406.     if(!$value) delete_post_meta($post->ID, $key); // Delete if blank
  407. }
  408.  
  409. foreach ($drivet_meta as $key => $value) { // Cycle through the $details_meta array!
  410.     if( $post->post_type == 'revision' ) return; // Don't store custom data twice
  411.     $value = implode(',', (array)$value); // If $value is an array, make it a CSV (unlikely)
  412.     if(get_post_meta($post->ID, $key, FALSE)) { // If the custom field already has a value
  413.         update_post_meta($post->ID, $key, $value);
  414.     } else { // If the custom field doesn't have a value
  415.         add_post_meta($post->ID, $key, $value);
  416.     }
  417.     if(!$value) delete_post_meta($post->ID, $key); // Delete if blank
  418. }
  419.  
  420. foreach ($intcol_meta as $key => $value) { // Cycle through the $details_meta array!
  421.     if( $post->post_type == 'revision' ) return; // Don't store custom data twice
  422.     $value = implode(',', (array)$value); // If $value is an array, make it a CSV (unlikely)
  423.     if(get_post_meta($post->ID, $key, FALSE)) { // If the custom field already has a value
  424.         update_post_meta($post->ID, $key, $value);
  425.     } else { // If the custom field doesn't have a value
  426.         add_post_meta($post->ID, $key, $value);
  427.     }
  428.     if(!$value) delete_post_meta($post->ID, $key); // Delete if blank
  429. }
  430.  
  431. foreach ($engine_meta as $key => $value) { // Cycle through the $details_meta array!
  432.     if( $post->post_type == 'revision' ) return; // Don't store custom data twice
  433.     $value = implode(',', (array)$value); // If $value is an array, make it a CSV (unlikely)
  434.     if(get_post_meta($post->ID, $key, FALSE)) { // If the custom field already has a value
  435.         update_post_meta($post->ID, $key, $value);
  436.     } else { // If the custom field doesn't have a value
  437.         add_post_meta($post->ID, $key, $value);
  438.     }
  439.     if(!$value) delete_post_meta($post->ID, $key); // Delete if blank
  440. }
  441.      
  442. // Style Forms
  443. echo '<style type="text/css">
  444.             .admin-col {
  445.                 display: inline-block;
  446.                 padding: 0 1rem 0 0;
  447.             }
  448.  
  449.             .col25 {
  450.                 width: 22%;
  451.             }
  452.  
  453.             .col33 {
  454.                 width: 31%;
  455.             }
  456.  
  457.             .p-heading {
  458.                 font-weight: 900;
  459.             }
  460.         </style>';
  461.  
  462. // Noncename needed to verify where the data originated
  463. echo '<input type="hidden" name="details_meta_noncename" id="eventmeta_noncename" value="' .
  464. wp_create_nonce( plugin_basename(__FILE__) ) . '" />';
  465.  
  466. // Get the details data if its already been entered
  467. $customer = get_post_meta($post->ID, '_customer', true);
  468.  
  469.  
  470. // Echo out the field
  471. echo '<div class="row">';
  472. echo '<div class="admin-col col25"><p class="p-heading">Customer name</p>';
  473. echo '<input type="text" name="_customer" value="' . $customer  . '" class="widefat" /></div>';
  474. echo '</div>';
  475.      
  476. // verify this came from the our screen and with proper authorization,
  477. // because save_post can be triggered at other times
  478. if ( !wp_verify_nonce( $_POST['details_meta_noncename'], plugin_basename(__FILE__) )) {
  479. return $post->ID;
  480. }
  481.  
  482. // Is the user allowed to edit the post or page?
  483. if ( !current_user_can( 'edit_post', $post->ID ))
  484.     return $post->ID;
  485.  
  486. // OK, we're authenticated: we need to find and save the data
  487. // We'll put it into an array to make it easier to loop though.
  488.  
  489. $customer_name_meta['_customer'] = $_POST['_customer'];
  490.  
  491. // Add values of $price_meta as custom fields
  492.  
  493. foreach ($customer_name_meta as $key => $value) { // Cycle through the $details_meta array!
  494.     if( $post->post_type == 'revision' ) return; // Don't store custom data twice
  495.     $value = implode(',', (array)$value); // If $value is an array, make it a CSV (unlikely)
  496.     if(get_post_meta($post->ID, $key, FALSE)) { // If the custom field already has a value
  497.         update_post_meta($post->ID, $key, $value);
  498.     } else { // If the custom field doesn't have a value
  499.         add_post_meta($post->ID, $key, $value);
  500.     }
  501.     if(!$value) delete_post_meta($post->ID, $key); // Delete if blank
  502. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top