[Resolved] Auto expire posts automatically and set status to draft
This thread is resolved. Here is a description of the problem and solution.
Problem:
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?
Solution:
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);
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.
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.
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.