Good day team
I would like to make it possible for the user to set the publication date, this way he can plan ahead. The intention is that the user creates the post and that, for example, this post will be published next week on the date and time that the user has set.
I have read a similar case on your site and started working with it (https://toolset.com/forums/topic/set-publish-date-of-post/)
In functions.php I have added the following code as indicated in the instruction:
add_action('cred_save_data', 'set_post_date_to', 100, 3);
function set_post_date_to($post_id, $form_data) {
if( $form_data['id'] == 349 ) {
$newDate = $_POST['set-new-date']['datetime'] . ' '.$_POST['set-new-date']['hour'].':'.$_POST['set-new-date']['minute'].':00';
$my_post = array(
'ID' => $post_id,
'post_date' => $newDate,
'post_date_gmt' => $newDate,
'post_status' => 'future'
);
// Update the post into the database
wp_update_post( $my_post );
}
}
In the form (ID349) that is used for creating the post, the generic data field is added:
[cred_generic_field type='date' field='set-new-date']
{
"required":1,
"validate_format":1
}
[/cred_generic_field]
What I notice is that on the form at the front end only the calendar is visible, not the time (See image)
I have tried but I don't get any time added. Is there a way to add time to the generic date field?
Without time, the user cannot set a time when the post must be published.
Thanks a lot for your support!
Greetings Pascal