wp_insert_post_data not working correctly on WordPress 5 (Gutenberg)
-
I have the following code in a project, that it worked before upgrading to WordPress 5, and what this used to do 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.
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 );According to the documentation of wp_insert_post_data, $data should have the post data and $postarr should have the unmodified post data. However, when 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? Is there an updated documentation?
Thanks
The topic ‘wp_insert_post_data not working correctly on WordPress 5 (Gutenberg)’ is closed to new replies.