I found a couple of issues in your code:
You need to replace: 'post_status' => 'published'
to 'post_status' => 'publish'
Also, if you want to get all posts, you need to add 'posts_per_page' => -1
So, the code will be like this:
$posts = get_posts( array(
'post_status' => 'publish',
'post_type' => 'post',
'posts_per_page' => -1,
));
$current_time = current_time('mysql');
$current_time_gmt = get_gmt_from_date( $current_time );
foreach( $posts as $post ) {
$update = array(
'ID' => $post->ID,
'post_date' => $current_time,
'post_date_gmt' => get_gmt_from_date( $current_time_gmt ),
);
wp_update_post( $update );
}
If you want to use custom post fields to save the date, you can try this example:
$posts = get_posts( array(
'post_status' => 'publish',
'post_type' => 'post',
'posts_per_page' => -1,
));
$current_time = current_time('mysql');
foreach( $posts as $post ) {
update_post_meta( $post->ID, 'custom_post_date', $current_time );
}
But if your site has many posts, these examples are not suitable because they result in multiple database requests.
I recommend using alternative methods. Here's an example for updating post data:
global $wpdb;
$current_time = current_time( 'mysql' );
$current_time_gmt = get_gmt_from_date( $current_time );
$wpdb->query(
$wpdb->prepare(
"UPDATE $wpdb->posts SET post_date = %s, post_date_gmt = %s
WHERE post_type = 'post' AND post_status='publish'",
$current_time,
$current_time_gmt
)
);
And here's an example for updating the custom post meta:
global $wpdb;
$current_time = current_time( 'mysql' );
$wpdb->query(
$wpdb->prepare(
"UPDATE $wpdb->postmeta SET meta_value = %s
WHERE post_id IN (SELECT ID FROM $wpdb->posts WHERE post_type = 'post' AND post_status='publish')
AND meta_key = 'custom_post_date'",
$current_time
)
);