TransWikia.com

Updating Media Published Date When Parent Post Is Modified in Wordpress

WordPress Development Asked by JimmyNeutron666 on December 1, 2021

I am hoping to make the published date of my media files always equal the modified date of the post it’s attached to.

e.g.

Image 1 (date: 1/1/20 5:00PM) is attached to Post 1 (date: 1/1/20 5:00PM)

Post 1 is updated on 1/2/20 5:00PM > Image 1 updates it’s published time in the db to 1/2/20 5:00PM

So far I have this function, and it works for the parent post to make the published time = modified time, but I need it to work on the child post (the image in post_meta db) rather than the parent.

function reset_post_date_wpse_121565($data,$postarr) {
    $data['post_date'] = $data['post_modified'];
    $data['post_date_gmt'] = $data['post_modified_gmt'];
    return $data;
}
              
add_filter('wp_insert_post_data','reset_post_date_wpse_121565',99,2);

So, how can I make this code above work for updating the published date of the image child post in post_meta?

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP