I have been able to set auto expire dates for a CPT (by updating '_cred_post_expiration_time') but I also need to set the new status of the post to private when the post expires.
Initial status is published.
How can I do that?

Mateus Getulio
Unterstützer
Sprachen:
Englisch (English )
Zeitzone:
America/Sao_Paulo (GMT-03:00)
Hi there,
Thanks for your contact!
When you open the form responsible for adding this CPT you'll see that the Toolset form editor has an option in the 'Settings' section for setting an 'Automatic Expiration Date' per form, as you might already know - from here, you can enable automatic expiration for the form, set the expiration time and you can also set what happens after expiration, related to the expired post status: https://toolset.com/wp-content/uploads/2014/08/cred-post-expiration-options-in-a-form-1.png.
Could you please take a look on these settings and check if you will be able to set a status for the expired posts? Also, don't forget to check our doc related: https://toolset.com/course-lesson/setting-up-automatic-post-expiration/
Looking forward to your reply. Thank you.
Kind regards,
Mateus.
Mateus,
I was not very clear in my posting. I would like to set the expiration post status programmatically. How can I do that?

Mateus Getulio
Unterstützer
Sprachen:
Englisch (English )
Zeitzone:
America/Sao_Paulo (GMT-03:00)
Hey there,
Thanks for the clarification, and sorry about this misunderstanding.
Could you please share with us the program and logic being used here for the expiration date? In order to check better if we have an easy fix which wouldn't require a big customization in the code.
Please keep us posted. Thank you.
Look at this post - https://toolset.com/forums/topic/expiration-for-posts/
It has a section --
If you also want the user to be able to customise this per post then you would need to update the _cred_post_expiration_action post meta as well.
This stores the status that will be applied upon expiration inside an array, something like this:
Array
(
[post_status] => draft
[custom_actions] => Array
(
)
)

Mateus Getulio
Unterstützer
Sprachen:
Englisch (English )
Zeitzone:
America/Sao_Paulo (GMT-03:00)
Hey there,
Thank you for clarifying it.
I double-checked it and currently we don't have a specific hook for what you're trying to achieve: https://toolset.com/documentation/programmer-reference/
Let me double-check internally if we have an easy application of this. I asked my colleagues to take a look to see if there's anything I'm missing.
I'll come back here as soon as one of them answers me (which shouldn't take long). Thank you in advance for your patience!
Regards,
Mateus.

Mateus Getulio
Unterstützer
Sprachen:
Englisch (English )
Zeitzone:
America/Sao_Paulo (GMT-03:00)
Hey there,
I checked it and you can use the '_cred_post_expiration_time' to set the status of the CPT to draft, for example.
For example, you can add the following code where you're changing the expiration date and this should cause the effect you need:
// set expiration action to 'draft' status
$new_status_arr = array( 'post_status' => 'draft', 'custom_actions' => array() );
update_post_meta($post_id, '_cred_post_expiration_action', $new_status_arr);
Please give it a try and let us know if works for you.
Best,
Mateus.