Skip Navigation

[Resolved] Post expiry date in form saves a different date in the post

This support ticket is created 3 years, 4 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 6 replies, has 2 voices.

Last updated by leilaG 3 years, 4 months ago.

Assisted by: Minesh.

Author
Posts
#2113491

Post expiry date in the form saving as different date in the actual post.

I have pushed a fresh copy of the live site to staging site

hidden link

I submitted this form with expiry date: 18/07/2021 when you go into the post the date is showing 10/08/2021
hidden link
hidden link

FYI - I removed recaptcha in the form as it was giving an error because it's the staging site/domain
ERROR for site owner: Invalid domain for site key
[cred_field field='recaptcha' value='' urlparam='' class='form-control' output='bootstrap']
<br>

#2114161

Minesh
Supporter

Languages: English (English )

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

Hello. Thank you for contacting the Toolset support.

Post expiration time is saved with the meta key namely "_cred_post_expiration_time" that holds the date field value as unix timestamp.

That is why we will require to save the timestamp with the post meta key "_cred_post_expiration_time".

I've added the following code to "Custom Code" section offered by Toolset:
=> hidden link

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']==17313){
		
        $expiry_date = $_POST['expiration-date']['timestamp'];
            update_post_meta($post_id, '_cred_post_expiration_time', $expiry_date );
    }
}

Where:
- 17313 is your original form ID.

More info:
=> https://toolset.com/documentation/programmer-reference/adding-custom-code/using-toolset-to-add-custom-code/
=> https://toolset.com/documentation/programmer-reference/cred-api/

I checked and I found that it works as expected and custom post expiration date is saved correctly - can you please confirm it works at your as well.

#2115089

Thank Minesh, strange it's worked for the last 3 years.

I tested on staging site, it's working again now, but I added the code to our live site and tested, but its not working on the live site. Are there any other settings or code I need to add or change?

#2115091

Minesh
Supporter

Languages: English (English )

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

No - I just added the code I shared and I can see it working. Please make sure you replace the original form ID, on staging its 17313 - it may be different on your live site.

#2115103
code.png
formID.png

Yes it's the same on the live site 17313, screenshots attached.

#2115189

Minesh
Supporter

Languages: English (English )

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

Is the code snippet you added is active? if not, can you please activate it. If that does not help I will require admin access details to your live site with problem URL where you added the form.

#2115403

My issue is resolved now. Thank you!