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
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/
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
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
Hi Lou, thanks for your reply . please see image attached.
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/
My issue is resolved now. Thank you!