Skip Navigation

[Resolved] Using form cred to set expiration date in Products

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

Problem:

Setup post expiration date in custom PHP codes.

Solution:

Toolset Forms plugin stores post expiration date as a custom field "_cred_post_expiration_time" in timestamp format, you just need to update the custom field "_cred_post_expiration_time" value, like this:

https://toolset.com/forums/topic/using-form-cred-to-set-expiration-date-in-products/#post-2210747

Relevant Documentation:

This support ticket is created 3 years 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/Hong_Kong (GMT+08:00)

This topic contains 6 replies, has 2 voices.

Last updated by camila 3 years ago.

Assisted by: Luo Yang.

Author
Posts
#2208845

Hi,
I am using the Form only to enable the expiration date on the products. I am not using the form for any front-end entry.
Right now I can set the expiration date on the product and set via save_post, but I cannot set the status to expired.

So basically on the save_post action, I am getting the date of a custom field ( $taxSale_date = get_post_meta( $post_id, 'wpcf-property-sale-date', true );
), then I am creating a product programatically and setting the expiration date:
update_post_meta($post_id, '_cred_post_expiration_post_status', 'wcm-expired');
that is working perfectly/

Now I would like to set the status to expired when that date passed, but I do not find a way to do it.

Can you help please with a recommendation?

Than ks

#2209795

Hello,

You can try action hook "cred_post_expiration_custom_actions":
https://toolset.com/documentation/programmer-reference/cred-api/#cred_post_expiration_custom_actions
for example:
1) when the post is expired, use action hook "cred_post_expiration_custom_actions" to trigger a custom PHP function
2) In this PHP function, get the "_cred_post_expiration_post_status" field value:
https://developer.wordpress.org/reference/functions/get_post_meta/
And update post status:
https://developer.wordpress.org/reference/functions/wp_update_post/

#2210103

Hi Luo,
thanks for your answer , but i am confused, If when I create a form on the settings I clicked After expiration change the status of the post to -> Expired.
Is that not supposed t happen automatically?
thanks

#2210585
expiration-status.jpg

To avoid more misunderstandings, please elaborate your questions with more details:

when I create a form on the settings I clicked After expiration change the status of the post to -> Expired.

Where and how do you "click After expiration change the status of the post to -> Expired" ?

I have tried it in a fresh WP installation with the latest version of Toolset plugins, I don't see any "Expired" post status in option "After expiration change the status of the post to" of post form, see my screenshot expiration-status.jpg

#2210735
Screen Shot 2021-11-02 at 6.46.09 AM.png

Hi Lou, thanks for your reply . please see image attached.

#2210747

So the "Expired" should be a custom post status.

Toolset Forms plugin stores post expiration date as a custom field "_cred_post_expiration_time" in timestamp format, you just need to update the custom field "_cred_post_expiration_time" value, like this:

$taxSale_date = get_post_meta( $post_id, 'wpcf-property-sale-date', true );
update_post_meta($post_id, '_cred_post_expiration_time', $taxSale_date);

More help:
https://developer.wordpress.org/reference/functions/update_post_meta/

#2214161

My issue is resolved now. Thank you!