Skip Navigation

[Gelöst] Form/Post expiration date

Dieser Thread wurde gelöst. Hier ist eine Beschreibung des Problems und der Lösung.

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 vor 2 Jahren, 9 Monaten. 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.

Heute stehen keine Supporter zur Arbeit im Werkzeugsatz-Forum zur Verfügung. Sie können gern Tickets erstellen, die wir bearbeiten werden, sobald wir online sind. Vielen Dank für Ihr Verständnis.

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)

Dieses Thema enthält 4 Antworten, hat 2 Stimmen.

Zuletzt aktualisiert von leilaG vor 2 Jahren, 9 Monaten.

Assistiert von: Waqar.

Author
Artikel
#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 versteckter 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!