Skip Navigation

[Resolved] Expire post based on custom field value

This support ticket is created 7 years, 2 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.

No supporters are available to work today on Toolset forum. Feel free to create tickets and we will handle it as soon as we are online. Thank you for your understanding.

Sun Mon Tue Wed Thu Fri Sat
- 9:00 – 18:00 9:00 – 18:00 9:00 – 18:00 9:00 – 18:00 9:00 – 18:00 -
- - - - - - -

Supporter timezone: Europe/Madrid (GMT+02:00)

Author
Posts
#492167

I am trying to: create a business directory for a chamber of commerce

I need to be able to have CPTs created via CRED forms that expire based on the time that the user last paid for their listing. I have two options: monthly, and annual. Based on which option the user chooses, I would like to have their business directory listing expire - after 30 days for monthly, or after 365 days for annual - which the user selects when they sign up and pay for their membership/directory listing.

#492421

Juan
Supporter

Timezone: Europe/Madrid (GMT+02:00)

Hi James

Currently, there is no dynamic way of setting a post expiration. The post expiration date is indeed stored in a custom field, in the shape of a timestamp, so there shoul not be too complex to hook into the CRED APi and set it manually, based on the user type (monthly or annual paying).

I did not completely get the request, I fear. Users with a monthly subscription should get their post expired... when their subscription expires? Or a month after the post was submitted?

However, there might be an easy way to do it, by going around the problem, if the request is the second.

You will probably have a way of knowing whether the current user submitting a post is a monthy or annual subscriber. I would probably create two forms to create posts, one with an expiration date of 4 weeks, and the other for an expiration date of 365 days (we really need an option for months and years there!). Then, when displaying the form, you can use the Views conditional output shortcode to display one or the other based on the current user data.

I know this is not entirely straight forward, but this might be the best solution without using code. Please consider that this is not something that can be added to a GUI directly, as it involvs:
- knowing how to determine which kind of user, monthy or annual subscriber, we are dealing with, and in general there might be an unknown number of different kind of user types.
- setting a different expiration date based on that data.
- craft a GUI that works with this requirement and also without it.

In case the posts need to get expired when the user sibscription expires too, I am sorry to say that the only solution I can see involves some code.

CRED provides an AP with hooks to extend its functinality for those edge or specific cases that it can not generally cover. I would probably go with one of the following actions for this request:
https://toolset.com/documentation/user-guides/cred-api/#csd
https://toolset.com/documentation/user-guides/cred-api/#csc

Hope it helps.

#492887

Essentially, what I need is the ability to expire posts per-POST (based on the value of a field), versus how it is now where the expiration is set per-FORM that created the post.

Your workaround solution will likely work for me, but it is far from elegant, and I know you guys can do better, hence the feature request. Anyhow, thank you!

#493291

Juan
Supporter

Timezone: Europe/Madrid (GMT+02:00)

Hi James

Thanks for the feedback

As I said, the expiratio date for a post is already stored in a postmeta value for that post, so it is indeed set on a per post basis when you create it. Other thing is that the date in which iit is expired is calculated from the one it was created plus some setting from the form itself.

We can do two things here:

You can use the hooks I provided earlier to modify that expiration date. When you submit a form that publishes a post, you can check the curent user, check the kind of subscription that he has, and update the postmeta storing the expiration date, as a timestamp, accordingly. The postmeta key where the expiration time for each post is stored is "_cred_post_expiration_time", and the expiration date is stored in the "cred_save_data" action with priority 10, so anythign hooked after that can modify the stored expiration date.

Other option is that we provide another hook, this time over the priod of time to add to the moent where the post is created, so you can hook into it, override the one coming from the form, and set the one you like based on the current user. But still, you will need to hook into it on PHP. As I explained above, there is no way to craft a GUI to cover your exact needs without pushing this edge case onto all the users. And honestly using the CRED hooks API this can already be done so here is little reason to act over it.

I can link to some documentation on how to use hooks in WordPress, what are priorities and which amount of arguments a hook is getting passed, but we do not provide code snippets as part of support. Anyway, the documentation for the hook that you would need to use includes an example of usage:
https://toolset.com/documentation/user-guides/cred-api/#csd

Hope it helps.

Regards.

This ticket is now closed. If you're a WPML client and need related help, please open a new support ticket.