I have the following code in a project.
function vb_post_modified_date_update($data, $postarr) {
if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE )
return;
if (!empty($postarr['vb_modified_date_switch'])) {
$data['post_modified'] = $postarr['post_modified'];
$data['post_modified_gmt'] = $postarr['post_modified_gmt'];
}
return $data;
}
add_filter( 'wp_insert_post_data', 'vb_post_modified_date_update', '99', 2 );
What this used to do (it worked before upgrading to Wordpress 5), is to keep the old value on post_modified
and post_modified_gmt
fields when saving the post and a checkbox (vb_modified_date_switch
) is checked in the post editor.
According documentation of wp_insert_post_data
, $data
should have the post data and $postarr
should have the unmodified post data. However, debuging, I found that both variables have the same post data (modified data), so now I cant get the original post_modified
and post_modified_gmt
.
Is there any other way I can change the post data before is saved?
Thanks