Advertisement
lauriemrauch

Custom Post Types Meta Content disappearing on updates

Nov 16th, 2011
58
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.29 KB | None | 0 0
  1. add_action('init', 'tours_register');
  2.  
  3. function tours_register() {
  4.  
  5. $labels = array(
  6. 'name' => _x('Tours', 'post type general name'),
  7. 'singular_name' => _x('New Tour', 'post type singular name'),
  8. 'add_new' => _x('Add New', 'tour'),
  9. 'add_new_item' => __('Add New Tour'),
  10. 'edit_item' => __('Edit Tour'),
  11. 'new_item' => __('New Tour'),
  12. 'view_item' => __('View Tour'),
  13. 'search_items' => __('Search Tours'),
  14. 'not_found' => __('Nothing found'),
  15. 'not_found_in_trash' => __('Nothing found in Trash'),
  16. 'parent_item_colon' => ''
  17. );
  18.  
  19. $args = array(
  20. 'labels' => $labels,
  21. 'public' => true,
  22. 'publicly_queryable' => true,
  23. 'show_ui' => true,
  24. 'query_var' => true,
  25. 'menu_icon' => get_stylesheet_directory_uri() . '/images/divasicon.png',
  26. 'rewrite' => true,
  27. 'capability_type' => 'post',
  28. 'hierarchical' => false,
  29. 'menu_position' => null,
  30. 'supports' => array('title', 'editor', 'thumbnail')
  31. );
  32.  
  33. register_post_type( 'tours' , $args );
  34. }
  35.  
  36.  
  37. add_action("admin_init", "admin_init");
  38.  
  39. function admin_init(){
  40. add_meta_box("tour_info", "Tour Information", "tour_info", "tours", "normal", "low");
  41. }
  42.  
  43. function tour_info(){
  44. global $post;
  45. $custom = get_post_custom($post->ID);
  46. $tour_when = $custom["tour_when"][0];
  47. $tour_duration = $custom["tour_duration"][0];
  48. $tour_where = $custom["tour_where"][0];
  49. $tour_google = $custom["tour_google"][0];
  50. $tour_walking = $custom["tour_walking"][0];
  51. $tour_price = $custom["tour_price"][0];
  52. $tour_home = $custom["tour_home"][0];
  53. $tour_link = $custom["tour_link"][0];
  54. ?>
  55. <style type="text/css">
  56. .tour label{float:left; line-height:30px; width:200px;}
  57. .tour input{width:300px;}
  58. </style>
  59. <p class="tour"><label>When:</label>
  60. <input name="tour_when" value="<?php echo $tour_when; ?>" /></p>
  61. <p class="tour"><label>Duration:</label>
  62. <input name="tour_duration" value="<?php echo $tour_duration; ?>" /></p>
  63. <p class="tour"><label>Where:</label>
  64. <input name="tour_where" value="<?php echo $tour_where; ?>" /></p>
  65. <p class="tour"><label>Google Maps URL:</label>
  66. <input name="tour_google" value="<?php echo $tour_google; ?>" /></p>
  67. <p class="tour"><label>Walking Time:</label>
  68. <input name="tour_walking" value="<?php echo $tour_walking; ?>" /></p>
  69. <p class="tour"><label>Ticket Price:</label>
  70. <input name="tour_price" value="<?php echo $tour_price; ?>" /><br />
  71. Enter only the ticket price, leave off the $ sign.</p>
  72. <p class="tour"><label>Sidebar text:</label>
  73. <input name="tour_home" value="<?php echo $tour_home; ?>" /></p>
  74. <p class="tour"><label>Link URL to buy tickets:</label>
  75. <input name="tour_link" value="<?php echo $tour_link; ?>" /></p>
  76.  
  77.  
  78.  
  79. <?php
  80. }
  81.  
  82. add_action('save_post', 'save_tour_details');
  83.  
  84. function save_tour_details(){
  85. global $post;
  86. if (defined(‘DOING_AUTOSAVE’) && DOING_AUTOSAVE) {
  87. return $post->ID;
  88. } else {
  89.  
  90. update_post_meta($post->ID, "tour_when", $_POST["tour_when"]);
  91. update_post_meta($post->ID, "tour_duration", $_POST["tour_duration"]);
  92. update_post_meta($post->ID, "tour_where", $_POST["tour_where"]);
  93. update_post_meta($post->ID, "tour_google", $_POST["tour_google"]);
  94. update_post_meta($post->ID, "tour_walking", $_POST["tour_walking"]);
  95. update_post_meta($post->ID, "tour_price", $_POST["tour_price"]);
  96. update_post_meta($post->ID, "tour_home", $_POST["tour_home"]);
  97. update_post_meta($post->ID, "tour_link", $_POST["tour_link"]);
  98. }
  99. }
  100. function save_tours_details(){
  101. global $post;
  102. if (defined(‘DOING_AUTOSAVE’) && DOING_AUTOSAVE) {
  103. return $post->ID;
  104. } else {
  105. update_post_meta($post->ID, "tour_when", $_POST["tour_when"]);
  106. update_post_meta($post->ID, "tour_duration", $_POST["tour_duration"]);
  107. update_post_meta($post->ID, "tour_where", $_POST["tour_where"]);
  108. update_post_meta($post->ID, "tour_google", $_POST["tour_google"]);
  109. update_post_meta($post->ID, "tour_walking", $_POST["tour_walking"]);
  110. update_post_meta($post->ID, "tour_price", $_POST["tour_price"]);
  111. update_post_meta($post->ID, "tour_home", $_POST["tour_home"]);
  112. update_post_meta($post->ID, "tour_link", $_POST["tour_link"]);
  113. }
  114. }
  115.  
  116. function save_tours(){
  117. global $post;
  118. if(!isset($_POST["tour_when"])):
  119. return $post;
  120. endif;
  121. update_post_meta($post->ID, "tour_when", $_POST["tour_when"]);
  122. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement