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

WordPress Trac noreply at wordpress.org
Thu Sep 25 16:59:03 UTC 2025


#62468: wp_update_post overwrites post_date when updating post_status
-------------------------------------------------+-------------------------
 Reporter:  aguerra07                            |       Owner:  (none)
     Type:  defect (bug)                         |      Status:  new
 Priority:  normal                               |   Milestone:  Future
                                                 |  Release
Component:  Posts, Post Types                    |     Version:
 Severity:  normal                               |  Resolution:
 Keywords:  has-patch needs-testing has-unit-    |     Focuses:
  tests                                          |
-------------------------------------------------+-------------------------

Comment (by sajjad67):

 == Test Report
 === Description
 This report validates whether the indicated patch works as expected.

 Patch tested: https://github.com/WordPress/wordpress-develop/pull/9699

 === Environment
 - WordPress: 6.9-alpha-60093-src
 - PHP: 8.2.29
 - Server: nginx/1.29.1
 - Database: mysqli (Server: 8.4.6 / Client: mysqlnd 8.2.29)
 - Browser: Chrome 140.0.0.0
 - OS: Windows 10/11
 - Theme: Twenty Twenty-Five 1.3
 - MU Plugins: None activated
 - Plugins:
   * Test Reports 1.2.0

 === Testing Instructions
 1. Use this code to create a new post with Pending Review Status or use
 UI:
 {{{
   function create_pending_post() {
     $post_data = array(
       'post_title'   => 'Pending Status Post',
       'post_content' => '',
       'post_status'  => 'pending',
       'post_author'  => 1,
       'post_type'    => 'post',
     );

     $post_id = wp_insert_post( $post_data );

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

   add_action( 'wp_ajax_create_pending_post', 'create_pending_post' );
 }}}

 2. Update the post status and post date:
 {{{
   function schedule_post_for_future() {
     $post_id     = 12;
     $future_date = '2025-09-30 22:00:00';
     if ( ! strtotime( $future_date ) ) {
       return 'Invalid date format';
     }

     $post_data = array(
       'ID'            => $post_id,
       'post_title'    => 'Future Status Post',
       '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 ) ) {
       die( 'Error updating post: ' . esc_html(
 $updated_post->get_error_message() ) );
     }

     die( 'Post successfully scheduled for: ' . esc_html( $future_date ) );
   }

   add_action( 'wp_ajax_schedule_post_for_future',
 'schedule_post_for_future' );
 }}}

 3. Check if the post is scheduled for the date in the future, or if its
 Published.

 [[Image(https://img001.prntscr.com/file/img001/B6-cKLPlTIqiwx8ofKYmJA.png)]]

 === Actual Results
 1.  ✅ Issue resolved with patch.

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


More information about the wp-trac mailing list