[wp-trac] [WordPress Trac] #62468: wp_update_post overwrites post_date when updating post_status

WordPress Trac noreply at wordpress.org
Tue Nov 19 05:51:04 UTC 2024


#62468: wp_update_post overwrites post_date when updating post_status
-------------------------+-------------------------------------------------
 Reporter:  aguerra07    |       Owner:  (none)
     Type:  defect       |      Status:  new
  (bug)                  |
 Priority:  normal       |   Milestone:  Awaiting Review
Component:  Posts, Post  |     Version:  6.7
  Types                  |
 Severity:  normal       |  Resolution:
 Keywords:  has-patch    |     Focuses:  performance, coding-standards,
  needs-testing          |  php-compatibility
-------------------------+-------------------------------------------------

Comment (by ankitkumarshah):

 Hi @aguerra07,

 Thank you for bringing this up.  I attempted to reproduce the issue, but I
 was unable to replicate it. Below are the details of my implementation:

 **My create_pending_post() Function:**

 {{{
 function create_pending_post() {
         $post_data = array(
                 'post_title'   => 'Your Post Title',
                 'post_content' => 'Your post content goes here.',
                 'post_status'  => 'pending',
                 'post_author'  => 1,
                 'post_type'    => 'post',
         );

         $post_id = wp_insert_post( $post_data );

         if ( ! is_wp_error( $post_id ) ) {
                 return 'Post created successfully with ID: ' . $post_id;
         } else {
                 return 'Error creating post: ' .
 $post_id->get_error_message();
         }
 }
 }}}

 **My schedule_post_for_future() Function**

 {{{
 function schedule_post_for_future( $post_id ) {
         $post_id     = 62;
         $future_date = '2024-12-25 14:30:00';
         if ( ! strtotime( $future_date ) ) {
                 return 'Invalid date format';
         }

         $post_data = array(
                 'ID'            => $post_id,
                 'post_status'   => 'future',
                 'post_date'     => $future_date,
                 'post_date_gmt' => get_gmt_from_date( $future_date ),
         );

         $updated_post = wp_update_post( $post_data, true );

         if ( is_wp_error( $updated_post ) ) {
                 return 'Error updating post: ' .
 $updated_post->get_error_message();
         }

         return 'Post successfully scheduled for: ' . $future_date;
 }
 }}}

 **My Post Dashboard:**

 [[Image(https://i.postimg.cc/WVHNSk2v/image.png)]]

 **Database Info:**

 [[Image(https://i.postimg.cc/mDxpvNwb/image.png)]]

 Could you please let me know if there’s something I might have overlooked
 or if there are additional steps I should try to reproduce the issue?

-- 
Ticket URL: <https://core.trac.wordpress.org/ticket/62468#comment:1>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list