Please, Who can help me with a function code that can display current date and time on all my single posts in WordPress instead of the published date?
I tried the code below but didn't work
$time = current_time('mysql');
$post_type = 'post'; // post, page, product or some other custom post type
// Get all the posts
$posts = get_posts( array(
'post_status' => 'published',
'post_type' => $post_type
));
foreach( $posts as $post ) {
// We only want to update the post date
$update = array(
'ID' => $post->ID,
'post_date' => $time,
'post_date_gmt' => get_gmt_from_date( $time ),
);
//* Update the post
wp_update_post( $update );
I tried the code below but didn't work
$time = current_time('mysql');
$post_type = 'post'; // post, page, product or some other custom post type
// Get all the posts
$posts = get_posts( array(
'post_status' => 'published',
'post_type' => $post_type
));
foreach( $posts as $post ) {
// We only want to update the post date
$update = array(
'ID' => $post->ID,
'post_date' => $time,
'post_date_gmt' => get_gmt_from_date( $time ),
);
//* Update the post
wp_update_post( $update );