Skip Navigation

[Resolved] Form/Post expiration date

This thread is resolved. Here is a description of the problem and solution.

Problem:
The customer reported that the code to set the post-expiration date/time through the 'cred_save_data' hook is not working as expected.

Solution:
Tested the customer's code and it worked as expected on a test website.

Guided that when using the custom function to set the expiration date/time, please make sure that the option 'Set expiration date for post created or edited by this form' is unchecked in the form's settings.

If you've set some post-expiration date/time through the form settings, it will override the date/time set by the custom function.

Relevant Documentation:
n/a

This support ticket is created 2 years, 9 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
- 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 9: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/Karachi (GMT+05:00)

This topic contains 4 replies, has 2 voices.

Last updated by leilaG 2 years, 9 months ago.

Assisted by: Waqar.

Author
Posts
#2292319

Hello!

We have a generic date field in the form and setting checked for Post expiration. We are using the below code, but it's not setting the correct date that the user inputs into the form hidden link
[cred_generic_field type='date' field='expiration-date']

add_action('cred_save_data', 'func_set_custom_post_expiration_date_time',10,2);
function func_set_custom_post_expiration_date_time($post_id, $form_data){
// if a specific form
if ($form_data['id']==4896){

$expiry_date = $_POST['expiration-date']['timestamp'];
update_post_meta($post_id, '_cred_post_expiration_time', $expiry_date );
}
}

#2292519

Hi,

Thank you for contacting us and I'd be happy to assist.

I tested the PHP function that you've shared and it worked as expected on my test website.

Here is the generic field code that I used in my form:


[cred_generic_field type='date' field='expiration-date']
{
"required":0,
"validate_format":0
}
[/cred_generic_field]

Note: The expiration date/time will be set to midnight time (12 am) of the selected date.

I hope this helps and please let me know how it goes.

regards,
Waqar

#2292723

Hi Wagner,

I have the below code, I have just submitted another post through the from with the date 02/03/2022 but the date in the post changed to 15/03/2022.

Is this because of the setting in the form is set to expire in 4 weeks.

How do I get the date to change to the date that's submitted in the form?

The code in the for:

[cred_generic_field type='date' field='expiration-date']
{
"required":1,
"validate_format":0,
"default":""
}
[/cred_generic_field]

#2292815

Thanks for writing back.

As you're using the custom function to set the expiration date/time, based on the generic field's value, please make sure that the option 'Set expiration date for post created or edited by this form' is unchecked in the form's settings.

If you've set some post-expiration date/time through the form settings, it will override the date/time set by the custom function.

#2292841

That was issue, the setting was checked. All working now. Thank you!