Advertisement
marjwyatt

Edit Adventure Custom Post - Called from Member Portal

May 22nd, 2012
276
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 7.46 KB | None | 0 0
  1. <?php
  2. /*
  3. Template Name: sherpa edit adventure
  4. */
  5. ?>
  6. <?php /* http://pastebin.com/m73LXuuG */ ?>
  7. <?php
  8. //$debug = print_r($_POST, true);
  9.   if( 'POST' == $_SERVER['REQUEST_METHOD'] && !empty( $_POST['action'] ) &&  $_POST['action'] == "edit_post" && isset($_POST['postid'])) {
  10. //    echo '1. Got here!';
  11.     $post_to_edit = array();
  12.     $post_to_edit = get_post($_POST['postid']); /* these are the fields that we are editing in the form below. you have to change them to your fields and you can add as many as you need. */
  13.     $title = $_POST['title']; // Adventure Name
  14.     $description = $_POST['description']; // Adventure Description
  15.     $latitude = $_POST['woo_maps_lat']; // Latitude custom field for updating map
  16.     $longitude = $_POST['woo-maps_long']; // Longitude custom field for updating map
  17.     $min_skill = $_POST['skill_levels']; // Update minimum skill level
  18.     $gear_provided = $_POST['gear_provided']; // Update gear provided
  19.     $gear_required = $_POST['gear_required']; // Update gear required
  20.     $food_bev = $_POST['food_beverage']; // Update supplied food/beverages
  21.     $transportation = $_POST['transportation_provided']; // Update provided transportation
  22.     $successurl = home_url('/guide-portal/');
  23.  
  24. /* this code will save the title and description into the post_to_edit array */
  25.  
  26.     $post_to_edit->post_title = $title;
  27.     $post_to_edit->post_content = $description;
  28.  
  29. /* honestly i can't really remember why i added this code but it is a must */
  30.  
  31.     $pid = wp_update_post($post_to_edit);
  32.  
  33. /* save taxonomies: post ID, form name, taxonomy name, if it appends(true) or rewrite(false) */
  34. /* here you have to change the "coupon_categories" and "coupon_tags" to the name of your taxonomies */
  35.  
  36. //  wp_set_post_terms($pid, array($_POST['cat']),'coupons_categories',false);
  37. //  wp_set_post_terms($pid, array($_POST['post_tags']),'coupons_tags',false);
  38.  
  39. //UPDATE CUSTOM FIELDS WITH THE NEW INFO
  40. //CHANGE TO YOUR CUSTOM FIELDS AND ADD AS MANY AS YOU NEED
  41.  
  42.     update_post_meta($pid, 'woo_maps_lat', $latitude); // Map latitude
  43.     update_post_meta($pid, 'woo-maps_long', $longitude); // Map longitude
  44.     update_post_meta($pid, 'skill_levels', $min_skill); // Minimum Skill Level
  45.     update_post_meta($pid, 'gear_provided', $gear_provided); // Gear Provided
  46.     update_post_meta($pid, 'gear_required', $gear_required); // Gear Required
  47.     update_post_meta($pid, 'food_beverage', $food_bev); // Food/Beverage
  48.     update_post_meta($pid, 'transportation_provided', $transportation); // Transportation
  49.  
  50. //REDIRECT USER WHERE EVER YOU WANT AFTER DONE EDITING
  51. // echo '2. Got here!';
  52. //  wp_redirect( 'http://sherpademo.co.cc/guide-portal/' );
  53. // header("Location: http://sherpademo.co.cc/guide-portal/");
  54.     wp_redirect( $successurl );
  55.  
  56.   } // end check for errors
  57.  
  58. ?>
  59.  
  60. <?php get_header(); ?>
  61. <?php include ( TEMPLATEPATH . '/search-form.php' ); ?>
  62. <?php $post_to_edit = get_post($_POST['postid']); ?>
  63. <div id="content" class="col-full">
  64.     <div id="main-single" class="col-left">
  65.     <div class="post">
  66. <!-- EDIT GUIDE PROFILE -->
  67.  
  68. <form id="edit_post" name="edit_post" method="post" action="" enctype="multipart/form-data">
  69.  
  70.     <!-- post name -->
  71.     <fieldset name="name">
  72.         <label for="title">Update Adventure Name:</label><br />
  73.         <input type="text" id="title" value="<?php echo $post_to_edit->post_title; ?>" tabindex="5" name="title" /> <!-- TITLE FIELD. NOTHING TO CHANGE -->
  74.     </fieldset>
  75.  
  76.     <!-- post Content -->
  77.     <fieldset class="content">
  78.         <label for="description">Update Adventure Description:</label><br />
  79.         <div class="ginput_container"><textarea id="description" cols="50" rows="10" tabindex="15" name="description"><?php echo $post_to_edit->post_content; ?></textarea></div> <!-- TEXT AREA OF CONTENT. NOTHING TO CHANGE -->
  80.     </fieldset>
  81.  
  82.     <!-- images -->
  83.     <!--<?php echo get_the_post_thumbnail( $post_to_edit->ID, array( 200, 150 ) ); ?><br /> <!-- WILL DISPLAY THE POST'S THUMBNAIL. YOU CAN CHANGE THE SIZE OF IT -->
  84.     <!--<input type="checkbox" name="c1" onclick="showMe('image', this)" > <!-- SCRIPT CHECK IF CHANGING IMAGE OR NOT. NOTHING TO CHANGE -->
  85.     <!--<fieldset id="image">
  86.         <label for="image">Choose Image:</label>
  87.         <input type="file" name="image" id="image" tabindex="30" value="" />
  88.     </fieldset>-->
  89.  
  90.     <h3>Update Map Coordinates</h3>
  91.  
  92.     <!-- BELOW ARE THE CUSTOM FIELDS. CHANGE THEM ADD OR REMOVE -->
  93.  
  94.     <fieldset class="woo_maps_lat">
  95.         <label for="woo_maps_lat">Change Latitude:</label><br />
  96.         <input type="text" value="<?php echo get_post_meta($post_to_edit->ID,'woo_maps_lat', true); ?>" id="woo_maps_lat" tabindex="20" name="woo_maps_lat" /> <!-- Map Latitude -->
  97.     </fieldset>
  98.  
  99.     <fieldset class="woo_maps_long">
  100.         <label for="woo_maps_long">Change Longitude:</label><br />
  101.         <input type="text" value="<?php echo get_post_meta($post_to_edit->ID,'woo_maps_long', true); ?>" id="woo_maps_long" tabindex="21" name="woo_maps_long" /> <!-- Map Longitude -->
  102.     </fieldset>
  103.  
  104.     <h3>Update Adventure Details</h3>
  105.  
  106.     <fieldset class="skill_levels">
  107.         <label for="skill_levels">Minimum Skill Level:</label><br />
  108.         <div class="ginput_container"><select tabindex="22" class="medium gfield_select" id="input_3_8" name="input_8"><option value="<?php echo get_post_meta($post_to_edit->ID,'skill_levels', true); ?>"><?php echo get_post_meta($post_to_edit->ID,'skill_levels', true); ?></option><option value="Expert">Expert</option><option value="Advanced">Advanced</option><option value="Intermediate">Intermediate</option><option value="Novice">Novice</option></select></div>
  109.     </fieldset>
  110.  
  111.     <fieldset class="gear_provided">
  112.         <label for="gear_provided">Update Gear Provided:</label><br />
  113.         <div class="ginput_container"><textarea id="gear_provided" cols="50" rows="10" tabindex="23" name="gear_provided"><?php echo get_post_meta($post_to_edit->ID,'gear_provided', true); ?></textarea></div> <!-- Gear Provided -->
  114.     </fieldset>
  115.  
  116.     <fieldset class="gear_required">
  117.         <label for="gear_required">Update Gear Required:</label><br />
  118.         <div class="ginput_container"><textarea id="gear_required" cols="50" rows="10" tabindex="24" name="gear_required"><?php echo get_post_meta($post_to_edit->ID,'gear_required', true); ?></textarea></div> <!-- Gear Required -->
  119.     </fieldset>
  120.  
  121.     <fieldset class="food_beverage">
  122.         <label for="food_beverage">Update Food/Beverages Provided:</label><br />
  123.         <div class="ginput_container"><textarea id="food_beverage" cols="50" rows="10" tabindex="25" name="food_beverage"><?php echo get_post_meta($post_to_edit->ID,'food_beverage', true); ?></textarea></div> <!-- Gear Required -->
  124.     </fieldset>
  125.  
  126.     <fieldset class="transportation_provided">
  127.         <label for="transportation_provided">Update Transportation Provided:</label><br />
  128.         <div class="ginput_container"><textarea id="transportation_provided" cols="50" rows="10" tabindex="25" name="transportation_provided"><?php echo get_post_meta($post_to_edit->ID,'transportation_provided', true); ?></textarea></div> <!-- Gear Required -->
  129.     </fieldset>
  130.  
  131.     <fieldset class="submit">
  132.         <input type="submit" value="Update Adventure" class="button gform_button" tabindex="40" id="submit" name="submit" /> <!-- SUBMIT BUTTON -->
  133.     </fieldset>
  134.     <input type="hidden" name="postid" value="<?php echo $post_to_edit->ID; ?>" /> <!-- DONT REMOVE OR CHANGE -->
  135.     <input type="hidden" name="action" value="edit_post" />                         <!-- DONT REMOVE OR CHANGE -->
  136.     <?php // wp_nonce_field( 'new-post' ); ?>
  137. </form>
  138.     <!-- END OF FORM -->
  139.  
  140.     </div><!-- post -->
  141.     </div><!-- main-single -->
  142.     <?php get_sidebar(); ?>
  143.     </div><!-- #content -->
  144.  
  145. <?php get_footer(); ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement