Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php /** Create Vehicle Listings Custom Post Type **/
- if ( 'listings' == $screen->post_type ) {
- $title = 'Model name';
- }
- return $title;
- <?php // Add the Car Details Meta Boxes
- // Style Forms
- echo '<style type="text/css">
- .admin-col {
- display: inline-block;
- padding: 0 1rem 0 0;
- }
- .col25 {
- width: 22%;
- }
- @media screen and (max-width: 39.9375em) {
- .col25 {
- width: 100%;
- }
- }
- .col33 {
- width: 31%;
- @media screen and (max-width: 39.9375em) {
- width: 100%;
- }
- }
- .p-heading {
- font-weight: 400;
- }
- .meta_fields input[type="text"], .meta_fields select {
- margin-bottom: 1rem;
- height: 3rem;
- }
- </style>';
- // Noncename needed to verify where the data originated
- echo '<input type="hidden" name="details_meta_noncename" id="eventmeta_noncename" value="' .
- wp_create_nonce( plugin_basename(__FILE__) ) . '" />';
- // SETUP TAXONOMY LISTS IN DROPDOWN SELECT MENU FOR MODEL YEAR AND MAKE
- ////// Model Years
- //Get taxonomy and terms
- $taxonomy = 'model_year';
- //Set up the taxonomy object and get terms
- $tax = get_taxonomy($taxonomy);
- $terms = get_terms($taxonomy,array('hide_empty' => 0, 'orderby' => 'name', 'order' => 'DESC'));
- //Name of the form
- $name = 'tax_input[' . $taxonomy . ']';
- //Get current and popular terms
- $popular = get_terms( $taxonomy, array( 'orderby' => 'count', 'order' => 'DESC', 'number' => 10, 'hierarchical' => false ) );
- $postterms = get_the_terms( $post->ID,$taxonomy );
- $current = ($postterms ? array_pop($postterms) : false);
- $current = ($current ? $current->term_id : 0);
- ////// Makes
- //Get taxonomy and terms
- $taxonomy_make = 'makes';
- //Set up the taxonomy object and get terms
- $tax_m = get_taxonomy($taxonomy_make);
- $terms_m = get_terms($taxonomy_make,array('hide_empty' => 0, 'orderby' => 'name', 'order' => 'ASC'));
- //Name of the form
- $name_m = 'tax_input[' . $taxonomy_make . ']';
- //Get current and popular terms
- $popular_m = get_terms( $taxonomy_make, array( 'orderby' => 'count', 'order' => 'DESC', 'number' => 10, 'hierarchical' => false ) );
- $postterms_m = get_the_terms( $post->ID,$taxonomy_make );
- $current_m = ($postterms_m ? array_pop($postterms_m) : false);
- $current_m = ($current_m ? $current_m->term_id : 0);
- ////// Body Types
- //Get taxonomy and terms
- $taxonomy_body_type = 'body_type';
- //Set up the taxonomy object and get terms
- $tax_body_type = get_taxonomy($taxonomy_body_type);
- $terms_body_type = get_terms($taxonomy_body_type,array('hide_empty' => 0, 'orderby' => 'name', 'order' => 'ASC'));
- //Name of the form
- $name_body_type = 'tax_input[' . $taxonomy_body_type . ']';
- //Get current and popular terms
- $popular_body_type = get_terms( $taxonomy_body_type, array( 'orderby' => 'count', 'order' => 'DESC', 'number' => 10, 'hierarchical' => false ) );
- $postterms_body_type = get_the_terms( $post->ID,$taxonomy_body_type );
- $current_body_type = ($postterms_body_type ? array_pop($postterms_body_type) : false);
- $current_body_type = ($current_body_type ? $current_body_type->term_id : 0);
- ////// Colors
- //Get taxonomy and terms
- $taxonomy_colors = 'colors';
- //Set up the taxonomy object and get terms
- $tax_colors = get_taxonomy($taxonomy_colors);
- $terms_colors = get_terms($taxonomy_colors,array('hide_empty' => 0, 'orderby' => 'name', 'order' => 'ASC'));
- //Name of the form
- $name_colors = 'tax_input[' . $taxonomy_colors . ']';
- //Get current and popular terms
- $popular_colors = get_terms( $taxonomy_colors, array( 'orderby' => 'count', 'order' => 'DESC', 'number' => 10, 'hierarchical' => false ) );
- $postterms_colors = get_the_terms( $post->ID,$taxonomy_colors );
- $current_colors = ($postterms_colors ? array_pop($postterms_colors) : false);
- $current_colors = ($current_colors ? $current_colors->term_id : 0);
- ////// Drivetrain
- //Get taxonomy and terms
- $taxonomy_drivetrain = 'drivetrain';
- //Set up the taxonomy object and get terms
- $tax_drivetrain = get_taxonomy($taxonomy_drivetrain);
- $terms_drivetrain = get_terms($taxonomy_drivetrain,array('hide_empty' => 0, 'orderby' => 'name', 'order' => 'ASC'));
- //Name of the form
- $name_drivetrain = 'tax_input[' . $taxonomy_drivetrain . ']';
- //Get current and popular terms
- $popular_drivetrain = get_terms( $taxonomy_drivetrain, array( 'orderby' => 'count', 'order' => 'DESC', 'number' => 10, 'hierarchical' => false ) );
- $postterms_drivetrain = get_the_terms( $post->ID,$taxonomy_drivetrain );
- $current_drivetrain = ($postterms_drivetrain ? array_pop($postterms_drivetrain) : false);
- $current_drivetrain = ($current_drivetrain ? $current_drivetrain->term_id : 0);
- ////// Transmissions
- //Get taxonomy and terms
- $taxonomy_transmissions = 'transmissions';
- //Set up the taxonomy object and get terms
- $tax_transmissions = get_taxonomy($taxonomy_transmissions);
- $terms_transmissions = get_terms($taxonomy_transmissions,array('hide_empty' => 0, 'orderby' => 'name', 'order' => 'ASC'));
- //Name of the form
- $name_transmissions = 'tax_input[' . $taxonomy_transmissions . ']';
- //Get current and popular terms
- $popular_transmissions = get_terms( $taxonomy_transmissions, array( 'orderby' => 'count', 'order' => 'DESC', 'number' => 10, 'hierarchical' => false ) );
- $postterms_transmissions = get_the_terms( $post->ID,$taxonomy_transmissions );
- $current_transmissions = ($postterms_transmissions ? array_pop($postterms_transmissions) : false);
- $current_transmissions = ($current_transmissions ? $current_transmissions->term_id : 0);
- ////// Fuel Type
- //Get taxonomy and terms
- $taxonomy_fuel_type = 'fuel-type';
- //Set up the taxonomy object and get terms
- $tax_fuel_type = get_taxonomy($taxonomy_fuel_type);
- $terms_fuel_type = get_terms($taxonomy_fuel_type,array('hide_empty' => 0, 'orderby' => 'name', 'order' => 'ASC'));
- //Name of the form
- $name_fuel_type = 'tax_input[' . $taxonomy_fuel_type . ']';
- //Get current and popular terms
- $popular_fuel_type = get_terms( $taxonomy_fuel_type, array( 'orderby' => 'count', 'order' => 'DESC', 'number' => 10, 'hierarchical' => false ) );
- $postterms_fuel_type = get_the_terms( $post->ID,$taxonomy_fuel_type );
- $current_fuel_type = ($postterms_fuel_type ? array_pop($postterms_fuel_type) : false);
- $current_fuel_type = ($current_fuel_type ? $current_fuel_type->term_id : 0);
- ////// Engine
- //Get taxonomy and terms
- $taxonomy_engine = 'engine';
- //Set up the taxonomy object and get terms
- $tax_engine = get_taxonomy($taxonomy_engine);
- $terms_engine = get_terms($taxonomy_engine,array('hide_empty' => 0, 'orderby' => 'name', 'order' => 'ASC'));
- //Name of the form
- $name_engine = 'tax_input[' . $taxonomy_engine . ']';
- //Get current and popular terms
- $popular_engine = get_terms( $taxonomy_engine, array( 'orderby' => 'count', 'order' => 'DESC', 'number' => 10, 'hierarchical' => false ) );
- $postterms_engine = get_the_terms( $post->ID,$taxonomy_engine );
- $current_engine = ($postterms_engine ? array_pop($postterms_engine) : false);
- $current_engine = ($current_engine ? $current_engine->term_id : 0);
- // Get the details data if its already been entered
- //$year = get_post_meta($post->ID, '_price', true);
- $price = get_post_meta($post->ID, '_price', true);
- $trim = get_post_meta($post->ID, '_trim', true);
- $mileage = get_post_meta($post->ID, '_mileage', true);
- $vin_num = get_post_meta($post->ID, '_vin', true);
- $tot = get_post_meta($post->ID, '_tot', true);
- $nod = get_post_meta($post->ID, '_nod', true);
- $drivet = get_post_meta($post->ID, '_drivet', true);
- $intcol = get_post_meta($post->ID, '_intcol', true);
- $engine = get_post_meta($post->ID, '_engine', true);
- // Echo out the field
- echo '<div class="meta_fields">';
- echo '<div class="row">';
- echo '<div class="admin-col col25"><p class="p-heading">Make</p>'; ?>
- <select id="<?php echo $taxonomy_make; ?>checklist" name="tax_input[makes]" class="form-no-clear" style="width: 100%;
- <select id="<?php echo $taxonomy; ?>checklist" name="tax_input[model_year]" class="form-no-clear" style="width: 100%;
- <?php
- echo '</div>';
- echo '<div class="admin-col col25"><p class="p-heading">Body Type</p>'; ?>
- <select id="<?php echo $taxonomy_body_type; ?>checklist" name="tax_input[body_type]" class="form-no-clear" style="width: 100%;
- <?php
- echo '</div>';
- echo '<div class="admin-col col25"><p class="p-heading">Color</p>'; ?>
- <select id="<?php echo $taxonomy_colors; ?>checklist" name="tax_input[colors]" class="form-no-clear" style="width: 100%;
- <?php
- echo '</div>';
- echo '</div>';
- echo '<div class="row">';
- echo '<div class="admin-col col25"><p class="p-heading">Drivetrain</p>'; ?>
- <select id="<?php echo $taxonomy_drivetrain; ?>checklist" name="tax_input[drivetrain]" class="form-no-clear" style="width: 100%;
- <?php
- echo '</div>';
- echo '<div class="admin-col col25"><p class="p-heading">Transmissions</p>'; ?>
- <select id="<?php echo $taxonomy_transmissions; ?>checklist" name="tax_input[transmissions]" class="form-no-clear" style="width: 100%;
- <?php
- echo '</div>';
- echo '<div class="admin-col col25"><p class="p-heading">Fuel Type</p>'; ?>
- <select id="<?php echo $taxonomy_fuel_type; ?>checklist" name="tax_input[fuel-type]" class="form-no-clear" style="width: 100%;
- <?php
- echo '</div>';
- echo '<div class="admin-col col25"><p class="p-heading">Engine</p>'; ?>
- <select id="<?php echo $taxonomy_engine; ?>checklist" name="tax_input[engine]" class="form-no-clear" style="width: 100%;
- <?php
- echo '</div>';
- echo '</div>';
- echo '<div class="row">';
- echo '<div class="admin-col col25"><p class="p-heading">Vin #</p>';
- echo '<input type="text" name="_vin" value="' . $vin_num . '" class="widefat" /></div>';
- echo '<div class="admin-col col25"><p class="p-heading">Mileage</p>';
- echo '<input type="text" name="_mileage" value="' . $mileage . '" class="widefat" /></div>';
- echo '<div class="admin-col col25"><p class="p-heading">Interior Color</p>';
- echo '<input type="text" name="_intcol" value="' . $intcol . '" class="widefat" /></div>';
- echo '<div class="admin-col col25"><p class="p-heading">Type of Title</p>';
- echo '<input type="text" name="_tot" value="' . $tot . '" class="widefat" /></div>';
- echo '</div>';
- echo '<div class="row">';
- echo '<div class="admin-col col25"><p class="p-heading">Number of Doors</p>';
- echo '<input type="text" name="_nod" value="' . $nod . '" class="widefat" /></div>';
- echo '<div class="admin-col col25"><p class="p-heading">Trim</p>';
- echo '<input type="text" name="_trim" value="' . $trim . '" class="widefat" /></div>';
- echo '<div class="admin-col col25"><p class="p-heading">Price</p>';
- echo '<input type="text" name="_price" value="' . $price . '" class="widefat" /></div>';
- echo '</div>';
- echo '</div>';
- // verify this came from the our screen and with proper authorization,
- // because save_post can be triggered at other times
- if ( !wp_verify_nonce( $_POST['details_meta_noncename'], plugin_basename(__FILE__) )) {
- return $post->ID;
- }
- // Is the user allowed to edit the post or page?
- if ( !current_user_can( 'edit_post', $post->ID ))
- return $post->ID;
- // OK, we're authenticated: we need to find and save the data
- // We'll put it into an array to make it easier to loop though.
- //$year_meta['_myear'] = $_POST['_myear'];
- //$makes_meta['_makes'] = $_POST['_makes'];
- //$body_type_meta['_body'] = $_POST['_body'];
- $details_meta['_price'] = $_POST['_price'];
- $trim_meta['_trim'] = $_POST['_trim'];
- $mileage_meta['_mileage'] = $_POST['_mileage'];
- $vin_num_meta['_vin'] = $_POST['_vin'];
- $tot_meta['_tot'] = $_POST['_tot'];
- $nod_meta['_nod'] = $_POST['_nod'];
- $drivet_meta['_drivet'] = $_POST['_drivet'];
- $intcol_meta['_intcol'] = $_POST['_intcol'];
- $engine_meta['_engine'] = $_POST['_engine'];
- // Add values of $price_meta as custom fields
- foreach ($details_meta as $key => $value) { // Cycle through the $details_meta array!
- if( $post->post_type == 'revision' ) return; // Don't store custom data twice
- $value = implode(',', (array)$value); // If $value is an array, make it a CSV (unlikely)
- if(get_post_meta($post->ID, $key, FALSE)) { // If the custom field already has a value
- update_post_meta($post->ID, $key, $value);
- } else { // If the custom field doesn't have a value
- add_post_meta($post->ID, $key, $value);
- }
- if(!$value) delete_post_meta($post->ID, $key); // Delete if blank
- }
- foreach ($trim_meta as $key => $value) { // Cycle through the $details_meta array!
- if( $post->post_type == 'revision' ) return; // Don't store custom data twice
- $value = implode(',', (array)$value); // If $value is an array, make it a CSV (unlikely)
- if(get_post_meta($post->ID, $key, FALSE)) { // If the custom field already has a value
- update_post_meta($post->ID, $key, $value);
- } else { // If the custom field doesn't have a value
- add_post_meta($post->ID, $key, $value);
- }
- if(!$value) delete_post_meta($post->ID, $key); // Delete if blank
- }
- foreach ($vin_num_meta as $key => $value) { // Cycle through the $details_meta array!
- if( $post->post_type == 'revision' ) return; // Don't store custom data twice
- $value = implode(',', (array)$value); // If $value is an array, make it a CSV (unlikely)
- if(get_post_meta($post->ID, $key, FALSE)) { // If the custom field already has a value
- update_post_meta($post->ID, $key, $value);
- } else { // If the custom field doesn't have a value
- add_post_meta($post->ID, $key, $value);
- }
- if(!$value) delete_post_meta($post->ID, $key); // Delete if blank
- }
- foreach ($makes_meta as $key => $value) { // Cycle through the $details_meta array!
- if( $post->post_type == 'revision' ) return; // Don't store custom data twice
- $value = implode(',', (array)$value); // If $value is an array, make it a CSV (unlikely)
- if(get_term_meta($term->term_id, $key, FALSE)) { // If the custom field already has a value
- update_term_meta($term->term_id, $key, $value);
- } else { // If the custom field doesn't have a value
- add_term_meta($term->term_id, $key, $value);
- }
- if(!$value) delete_term_meta($post->ID, $key); // Delete if blank
- }
- foreach ($year_meta as $key => $value) { // Cycle through the $details_meta array!
- if( $post->post_type == 'revision' ) return; // Don't store custom data twice
- $value = implode(',', (array)$value); // If $value is an array, make it a CSV (unlikely)
- if(get_term_meta($term->term_id, $key, FALSE)) { // If the custom field already has a value
- update_term_meta($term->term_id, $key, $value);
- } else { // If the custom field doesn't have a value
- add_term_meta($term->term_id, $key, $value);
- }
- if(!$value) delete_term_meta($post->ID, $key); // Delete if blank
- }
- /*foreach ($body_type_meta as $key => $value) { // Cycle through the $details_meta array!
- if( $post->post_type == 'revision' ) return; // Don't store custom data twice
- $value = implode(',', (array)$value); // If $value is an array, make it a CSV (unlikely)
- if(get_term_meta($term->term_id, $key, FALSE)) { // If the custom field already has a value
- update_term_meta($term->term_id, $key, $value);
- } else { // If the custom field doesn't have a value
- add_term_meta($term->term_id, $key, $value);
- }
- if(!$value) delete_term_meta($post->ID, $key); // Delete if blank
- }*/
- foreach ($mileage_meta as $key => $value) { // Cycle through the $details_meta array!
- if( $post->post_type == 'revision' ) return; // Don't store custom data twice
- $value = implode(',', (array)$value); // If $value is an array, make it a CSV (unlikely)
- if(get_post_meta($post->ID, $key, FALSE)) { // If the custom field already has a value
- update_post_meta($post->ID, $key, $value);
- } else { // If the custom field doesn't have a value
- add_post_meta($post->ID, $key, $value);
- }
- if(!$value) delete_post_meta($post->ID, $key); // Delete if blank
- }
- foreach ($tot_meta as $key => $value) { // Cycle through the $details_meta array!
- if( $post->post_type == 'revision' ) return; // Don't store custom data twice
- $value = implode(',', (array)$value); // If $value is an array, make it a CSV (unlikely)
- if(get_post_meta($post->ID, $key, FALSE)) { // If the custom field already has a value
- update_post_meta($post->ID, $key, $value);
- } else { // If the custom field doesn't have a value
- add_post_meta($post->ID, $key, $value);
- }
- if(!$value) delete_post_meta($post->ID, $key); // Delete if blank
- }
- foreach ($nod_meta as $key => $value) { // Cycle through the $details_meta array!
- if( $post->post_type == 'revision' ) return; // Don't store custom data twice
- $value = implode(',', (array)$value); // If $value is an array, make it a CSV (unlikely)
- if(get_post_meta($post->ID, $key, FALSE)) { // If the custom field already has a value
- update_post_meta($post->ID, $key, $value);
- } else { // If the custom field doesn't have a value
- add_post_meta($post->ID, $key, $value);
- }
- if(!$value) delete_post_meta($post->ID, $key); // Delete if blank
- }
- foreach ($drivet_meta as $key => $value) { // Cycle through the $details_meta array!
- if( $post->post_type == 'revision' ) return; // Don't store custom data twice
- $value = implode(',', (array)$value); // If $value is an array, make it a CSV (unlikely)
- if(get_post_meta($post->ID, $key, FALSE)) { // If the custom field already has a value
- update_post_meta($post->ID, $key, $value);
- } else { // If the custom field doesn't have a value
- add_post_meta($post->ID, $key, $value);
- }
- if(!$value) delete_post_meta($post->ID, $key); // Delete if blank
- }
- foreach ($intcol_meta as $key => $value) { // Cycle through the $details_meta array!
- if( $post->post_type == 'revision' ) return; // Don't store custom data twice
- $value = implode(',', (array)$value); // If $value is an array, make it a CSV (unlikely)
- if(get_post_meta($post->ID, $key, FALSE)) { // If the custom field already has a value
- update_post_meta($post->ID, $key, $value);
- } else { // If the custom field doesn't have a value
- add_post_meta($post->ID, $key, $value);
- }
- if(!$value) delete_post_meta($post->ID, $key); // Delete if blank
- }
- foreach ($engine_meta as $key => $value) { // Cycle through the $details_meta array!
- if( $post->post_type == 'revision' ) return; // Don't store custom data twice
- $value = implode(',', (array)$value); // If $value is an array, make it a CSV (unlikely)
- if(get_post_meta($post->ID, $key, FALSE)) { // If the custom field already has a value
- update_post_meta($post->ID, $key, $value);
- } else { // If the custom field doesn't have a value
- add_post_meta($post->ID, $key, $value);
- }
- if(!$value) delete_post_meta($post->ID, $key); // Delete if blank
- }
- // Style Forms
- echo '<style type="text/css">
- .admin-col {
- display: inline-block;
- padding: 0 1rem 0 0;
- }
- .col25 {
- width: 22%;
- }
- .col33 {
- width: 31%;
- }
- .p-heading {
- font-weight: 900;
- }
- </style>';
- // Noncename needed to verify where the data originated
- echo '<input type="hidden" name="details_meta_noncename" id="eventmeta_noncename" value="' .
- wp_create_nonce( plugin_basename(__FILE__) ) . '" />';
- // Get the details data if its already been entered
- $customer = get_post_meta($post->ID, '_customer', true);
- // Echo out the field
- echo '<div class="row">';
- echo '<div class="admin-col col25"><p class="p-heading">Customer name</p>';
- echo '<input type="text" name="_customer" value="' . $customer . '" class="widefat" /></div>';
- echo '</div>';
- // verify this came from the our screen and with proper authorization,
- // because save_post can be triggered at other times
- if ( !wp_verify_nonce( $_POST['details_meta_noncename'], plugin_basename(__FILE__) )) {
- return $post->ID;
- }
- // Is the user allowed to edit the post or page?
- if ( !current_user_can( 'edit_post', $post->ID ))
- return $post->ID;
- // OK, we're authenticated: we need to find and save the data
- // We'll put it into an array to make it easier to loop though.
- $customer_name_meta['_customer'] = $_POST['_customer'];
- // Add values of $price_meta as custom fields
- foreach ($customer_name_meta as $key => $value) { // Cycle through the $details_meta array!
- if( $post->post_type == 'revision' ) return; // Don't store custom data twice
- $value = implode(',', (array)$value); // If $value is an array, make it a CSV (unlikely)
- if(get_post_meta($post->ID, $key, FALSE)) { // If the custom field already has a value
- update_post_meta($post->ID, $key, $value);
- } else { // If the custom field doesn't have a value
- add_post_meta($post->ID, $key, $value);
- }
- if(!$value) delete_post_meta($post->ID, $key); // Delete if blank
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement