I want front end form to add new post with pending for review status and future publish date.
I use this solution: https://toolset.com/forums/topic/set-publish-date-of-post/
Pending status works great but publish date doesn't work neither with custom date field neither with standard date field.
to be clear here is my current code:
add_action('cred_save_data', 'set_post_date_to', 100, 3);
function set_post_date_to($post_id, $form_data) {
if( $form_data['id'] == 1518083 ) {
//$newDate = $_POST['set-new-date']['datetime'] . ' 00:00:00';
$newDate = $_POST['wpcf-post-publishdate']['datetime'] . ' '.$_POST['wpcf-post-publishdate']['hour'].':'.$_POST['wpcf-post-publishdate']['minute'].':00';
$my_post = array(
'ID' => $post_id,
'post_date' => $newDate,
'post_date_gmt' => $newDate,
'post_status' => 'pending'
);
// Update the post into the database
wp_update_post( $my_post );
}
}
Nigel
Supporter
Languages:
English (English )
Spanish (Español )
Timezone:
Europe/London (GMT+00:00)
To update the date it seems that you also need to pass an argument 'edit_date' => true for the date to be changed.
See https://developer.wordpress.org/reference/functions/wp_update_post/#comment-4418
It works perfectly! Thank a lot!