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
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?
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.
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".
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.
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.