[wp-trac] [WordPress Trac] #25023: WordPress 3.6 deleting data on custom post meta

WordPress Trac noreply at wordpress.org
Tue Aug 13 15:03:12 UTC 2013


#25023: WordPress 3.6 deleting data on custom post meta
--------------------------+---------------------------------------
 Reporter:  cdwharton     |      Owner:
     Type:  defect (bug)  |     Status:  new
 Priority:  normal        |  Milestone:  Awaiting Review
Component:  General       |    Version:  3.6
 Severity:  critical      |   Keywords:  needs-patch needs-testing
--------------------------+---------------------------------------
 Everything worked fine in WordPress 3.5 but after upgrading to WordPress
 3.6 and then simply editing (not saving) a post with custom post meta
 caused all custom post meta to be cleared and deleted from the database.

 Here is the code I am using to generate and save the custom meta.
 Admittedly it is a bit old now. I haven't been able to narrow down the
 issue other than I think it is something in the save function causing the
 issue, maybe the autosave?

 The main concern is that the data is there until you edit, when you edit
 (and do not save) it deletes.

 /* #######################################################################

         Custom Meta for Page Summary

 ####################################################################### */

         function page_summary_init(){
                         add_meta_box("page_summary-meta", __("Enter the
 page summary" , "textdomain"), "page_summary_meta_options", "page",
 "normal", "high");
                         add_meta_box("page_summary-meta", __("Enter the
 page summary" , "textdomain"), "page_summary_meta_options", "case_study",
 "normal", "high");
         }

         function page_summary_meta_options(){
                 global $post;
                 $custom = get_post_custom($post->ID);

                 $page_summary = "";

                 if( isset( $custom["page_summary"] ) ) {
                         $page_summary = $custom["page_summary"][0];
                 }

 ?>
         <div>
                 <div style="padding: 10px 0;"><i><b><?php _e("If this page
 is a sub page, you can enter the page summary here and it will be fed up
 to the landing page." , "textdomain"); ?></b></i></div>
                 <textarea class="large-text" rows="10" name="page_summary"
 id="page_summary"><?php echo $custom["page_summary"][0]; ?></textarea> <br
 />
         </div>
 <?php
         }

 function save_page_summary_meta(){
         global $post;
         if (isset( $post->post_type) && $post->post_type == 'page' ||
 $post->post_type == 'case_study' ){
                 if (defined('DOING_AUTOSAVE') && DOING_AUTOSAVE) {
                 return $post->ID;
                 } else {
                         if( isset( $post->ID ) ) {
                                 update_post_meta($post->ID,
 "page_summary", $_POST["page_summary"]);
                         }
                 }
         }
 }

 add_action("admin_init", "page_summary_init");
 add_action('save_post', 'save_page_summary_meta');

--
Ticket URL: <http://core.trac.wordpress.org/ticket/25023>
WordPress Trac <http://core.trac.wordpress.org/>
WordPress blogging software


More information about the wp-trac mailing list