Change the post date from a meta box
-
01-11-2019 - |
Question
I'm having a problem with updating the post_date in a custom function I've written.
I'm trying to change the "post_date" to my custom "meta_date" value.
Here is the function:
function cfc_reset_postdate( $data, $postarr ) {
// If it is our form has not been submitted, so we dont want to do anything
if(defined('DOING_AUTOSAVE') && DOING_AUTOSAVE) return;
if($data['post_type'] == 'scripture-memory') {
$date = get_post_meta( get_the_ID(), 'cfc_date', true );
$date = DateTime::createFromFormat('D - M j, Y', $date);
$date = $date->format('Y-m-d');
$data['post_date'] = $date;
return $data;
}
add_filter( 'wp_insert_post_data', 'cfc_reset_postdate', '10', 2);
I've tried linking it to all these filters but none seem to work...
It works, except I have to press the "Update" button twice to change the post_date to match my new meta date.
What am I doing wrong?
No correct solution
Licensed under: CC-BY-SA with attribution
Not affiliated with wordpress.stackexchange