Changing the post date and time with function

Call wp_update_post() with a special value for 'post_date' and 'post_date_gmt':

$time = current_time('mysql');

wp_update_post(
    array (
        'ID'            => 123, // ID of the post to update
        'post_date'     => $time,
        'post_date_gmt' => get_gmt_from_date( $time )
    )
);

Leave a Comment