Home › Forums › Front-end Issues › Updating post modified date › Reply To: Updating post modified date
Ok, thanks. I think I was able to get this working. The post_modified date is now updating when we edit on the front end. However, I am also seeing new errors pop up with another plugin, so not sure if I did this right. (It’s possible these errors may not be related.)
I’m not that familiar with the wpdb class so let me know if anything looks incorrect.
Here is my code:
function my_acf_save_post( $post_id ) {
// bail out early if we don't need to update the date
if( is_admin() || $post_id == 'new' ) {
return;
}
global $wpdb;
$datetime = date("Y-m-d H:i:s");
$query = "UPDATE $wpdb->posts
SET
post_modified = '$datetime'
WHERE
ID = '$post_id'";
$wpdb->query( $query );
}
// run after ACF saves the $_POST['acf'] data
add_action('acf/save_post', 'my_acf_save_post', 20);
Thanks!
Welcome to the Advanced Custom Fields community forum.
Browse through ideas, snippets of code, questions and answers between fellow ACF users
Helping others is a great way to earn karma, gain badges and help ACF development!
We use cookies to offer you a better browsing experience, analyze site traffic and personalize content. Read about how we use cookies and how you can control them in our Cookie Policy. If you continue to use this site, you consent to our use of cookies.