Skip Navigation

[Resolved] CRED Post Expiration – how to set using a function

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

Problem: I would like to set the CRED post expiration date using code, and I would like to be able to turn the automatic expiration checkbox on or off programmatically as well.

Solution: You can modify a post's automatic expiration date by setting the value of the hidden postmeta field "_cred_post_expiration_date". If you remove the postmeta field, the checkbox is unchecked. If you add the postmeta field, the checkbox is checked. There is no separate field to store checkbox on vs. checkbox off.

This support ticket is created 6 years, 7 months 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
8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 - -
13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 - -

Supporter timezone: America/New_York (GMT-04:00)

Tagged: 

This topic contains 6 replies, has 2 voices.

Last updated by Charlie 6 years, 7 months ago.

Assisted by: Christian Cox.

Author
Posts
#680545

I am creating a classifieds site where each user has only one classified post.

I would like to do a couple of things using functions. For the logged in user:

Set/unset the check box 'Automatic expire date for this post'

Change the expiration date for a post

#680706

Hi, the CRED expiration date is stored as a timestamp in the postmeta table under the meta name '_cred_post_expiration_date'. If you remove this value, the checkbox will be unchecked. If you add this value, the checkbox will be checked and the expiration date and time will be set by the timestamp. You can do this with the update_post_meta WordPress API, but I'm not clear about how you want to trigger this change. For example, do you want to set the checkbox and expiration date when the CRED form is submitted, or when a User visits a certain page on your site? What will the new expiration date be - how is that determined?

#680818

I am using the Woocommerce Subscriptions plugin.
My plan is to have both free and subscription listings.
A user can set up a free listing which has an expiry set.
If the user subscribes to a paid plan (Active) then the checkbox 'Automatic expire date for this post' is set to unchecked and the post never expires.
If the user suspends or cancels the subscription (not Active) then the checkbox is checked again and the original expiry date reintated.

Woocommerce provides actions which would facilitate this given I have the correct code to set or unset the checkbox.

I suppose one way would be to have a custom post field and copy the expiry date to that so that it could be written back again if required. However, I would rather not have another field. Checking and unchecking the box would be better.

#680997

Unfortunately it would require another custom field, like you described. The checkbox and the timestamp are not separate entities in our system, so there is no record of the original expiration time if you remove the original value to uncheck the box. You could use a hidden custom field so it's not visible in wp-admin. Don't create the field in Types, just use update_post_meta to get or set the value in code using a field name like "_orig_expiry_date".

#681146

OK thank you.

I just thought it would be possible as in the post you can manually uncheck the box and the expire date is hidden. Then check it again and the expire date is back.

#681148

As far as I know you can only do that while you're editing the post. Once you save the post, that old expiration date goes away forever.

#681149

Oh I see.

Thank you for your help.