Skip Navigation

[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);

Relevant Documentation:
https://toolset.com/course-lesson/setting-up-automatic-post-expiration/

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 – 12:00 9:00 – 12:00 9:00 – 12:00 9:00 – 12:00 9:00 – 12:00 -
- 13:00 – 18:00 13:00 – 18:00 13:00 – 18:00 13:00 – 18:00 13:00 – 18:00 -

Supporter timezone: America/Sao_Paulo (GMT-03:00)

Tagged: 

This topic contains 7 replies, has 2 voices.

Last updated by Mateus Getulio 1 year, 4 months ago.

Assisted by: Mateus Getulio.

Author
Posts
#2627881

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?

#2628089

Mateus Getulio
Supporter

Languages: English (English )

Timezone: 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.

#2628139

Mateus,

I was not very clear in my posting. I would like to set the expiration post status programmatically. How can I do that?

#2628247

Mateus Getulio
Supporter

Languages: English (English )

Timezone: 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.

#2628249

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
        (
        )
)
#2628821

Mateus Getulio
Supporter

Languages: English (English )

Timezone: 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.

#2628923

Thank you

#2629113

Mateus Getulio
Supporter

Languages: English (English )

Timezone: 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.

#2629221

Thank you. This worked!