Skip Navigation

[Resolved] Add time Cred Generic Field Date

This support ticket is created 5 years, 2 months ago. There's a good chance that you are reading advice that it now obsolete.

This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.

Sun Mon Tue Wed Thu Fri Sat
- 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 -
- 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 -

Supporter timezone: Asia/Kolkata (GMT+05:30)

This topic contains 4 replies, has 2 voices.

Last updated by pascalH 5 years, 1 month ago.

Assisted by: Minesh.

Author
Posts
#1391863
only-date.JPG

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

#1392215

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

Hello. Thank you for contacting the Toolset support.

As I understand - you want to update the post_date value that is actually published date of post with date and time.

With Toolset generic date field there is no time option available, what as a workaround, what if you try to add a custom date field to your custom field group and set this field to display date and time and regenerate your form so the newly created date field will be available.

Maybe you can use/consider this newly created date/time field for further process or you can update the post_date value based on this newly created date/time field value. Please let me know your review on this workaround.

#1392659

Hello Minesh

Thanks for your reply, I will try and let the result now.

Greetings Pascal

#1392939

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

Sure. Please let me know if you need further help.

#1394953

Hello Minesh

I created a custom post field for date and time and used the code I specified earlier.
I tested it and it worked! Thanks for the advice.

Greetings Pascal