• You MUST read the Babiato Rules before making your first post otherwise you may get permanent warning points or a permanent Ban.

    Our resources on Babiato Forum are CLEAN and SAFE. So you can use them for development and testing purposes. If your are on Windows and have an antivirus that alerts you about a possible infection: Know it's a false positive because all scripts are double checked by our experts. We advise you to add Babiato to trusted sites/sources or disable your antivirus momentarily while downloading a resource. "Enjoy your presence on Babiato"

Help!!! Post Meta to Display Current Date & Time Instead of Published Date

glier5

New member
May 6, 2022
24
1
3
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 );
 
AdBlock Detected

We get it, advertisements are annoying!

However in order to keep our huge array of resources free of charge we need to generate income from ads so to use the site you will need to turn off your adblocker.

If you'd like to have an ad free experience you can become a Babiato Lover by donating as little as $5 per month. Click on the Donate menu tab for more info.

I've Disabled AdBlock