Skip Navigation

[Resolved] Display WordPress Post Expiration on Front End

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

Supporter timezone: Asia/Hong_Kong (GMT+08:00)

This topic contains 14 replies, has 2 voices.

Last updated by neilR 1 year, 5 months ago.

Assisted by: Luo Yang.

Author
Posts
#2609293

Tell us what you are trying to do?
I have a form which sets post expiration. I want to display the post expiration date on the front end.

Is there any documentation that you are following?
https://toolset.com/course-lesson/setting-up-automatic-post-expiration/

There doesn't seem to be any documentation on how to display the post expiration date, e.g. in a content template... Please advise?

#2609297

Forgot to ask also - can this field be edited with CRED on the front-end?

#2609501

Hello,

Q1) display the post expiration date on the front end
It is possible to display the post expiration value with shortcode, for example:
[cred-post-expiration format="m/d/Y"]

Q2) can this field be edited with CRED on the front-end?
Yes, it is possible, see below sandbox website:
Login URL: hidden link
1) Dashboard-> Toolset-> Post Forms, click button "Manage non-Toolset Post Fields"
hidden link
find and enable the hidden field "_cred_post_expiration_time"

2) In your post form for editing post:
hidden link
You can display above custom field,

3) Test it in frontend:
hidden link

It works fine

#2609615
2023-05-24_11-47-25.jpg

Hi Luo,

Q1-Thank you for the information - apologies, I missed cred-post-expiration in the Forms documentation.
Q2- I have taken a look at your sandbox, then tried to follow the same in my admin, but the _cred fields don't appear in the list (see attached - I checked against posts and pages and took the screenshot for the latter, hence it showing there).
2.1 The expiration event doesn't seem to be firing, despite having set the schedule to 'every 5 minutes'. I've installed WP Crontrol to take a look at crons (assuming this is what is used to schedule expiration processes) and there doesn't seem to be an entry in the list, either for schedule or events. Our host disables WP-CRON and uses the hosting cron to run events, but events are running successfully for AutomateWoo and other plugins...

#2609663
2023-05-24_14-29-16.jpg
2023-05-24_14-28-29.jpg

For info, screenshots attached show expiration settings in Toolset > Settings > Forms, and an example post whose expiration was set via a form submission - expiration in the past, but Post Status isn't changing to 'Trash'.

New threads created by Luo Yang and linked to this one are listed below:

https://toolset.com/forums/topic/post-status-isnt-changing/

#2609951

Q2) I can not reproduce the same problem, it works fine in the sandbox website, can you reproduce the same problem in above sandbox website?
Are you using the latest version of Toolset plugins? you can download them here:
https://toolset.com/account/downloads/

According to our support policy, we prefer one ticket one question, for other new issues please check the new thread here:
https://toolset.com/forums/topic/post-status-isnt-changing/

#2610409
2023-05-26_11-26-57.jpg

Hi Luo,
Plugins are all up-to-date.
I have gone looking for the same in another site, and cannot see the _cred_post_expiration_time in non-Toolset post fields.
This other site is on GeneratePress with very few plugins installed, so it seems unlikely to be a plugin conflict.
Is there something else I need to enable in order to see the field...?

#2610437

I have also created a blank site to test this on, and cannot see that field. I can provide you with Admin login to take a look if you want.

#2610963

OK, please provide your blank website credentials in below private message box.

#2611453

Thanks for the details, I am checking it in your website, will update here if find anything

#2611471

The problem is, in the Dashboard page:
hidden link
The select field "Select a post type" does not outputs post types created with Toolset Types by default, it works for post types created with other plugins.

In your case, you can try these:
Edit Toolset Forms plugin file: cred-frontend-editor/library/toolset/cred/embedded/models/Fields.php
hidden link
Change line 105 from:
$wpcf_custom_types = get_option( 'wpcf-custom-types', false );
To:
//$wpcf_custom_types = get_option( 'wpcf-custom-types', false );

Then try again:
hidden link
You will be able to add the custom field "_cred_post_expiration_time", and add it into Toolset post forms.

After that you can restore the "Fields.php" back.

#2611807
2023-06-01_07-39-22.jpg

Hi Luo,
Thanks for that. I've made the change you suggested to my test site. I note that the change works for a post type of 'Post', but when I change the form to create a CPT ('Expiring Thing'), the field does not work. I don't get the option to add it in the form creation wizard, and if I add it manually in expert mode, the front end throws an error, as before.

#2615721

Sorry for the delay answer, I have tried it again in below sand box website, it works fine:
Login URL: hidden link
1) Create a custom post type "Expiring Thing"
hidden link
2) Comment out line 105:
hidden link
3) Test it again:
hidden link
I can select custom post type "Expiring Thing" correctly, can you reproduce the same problem in above test site?

#2616589
2023-06-17_07-21-13.jpg

Hi Luo,
Thank you for the reply. I've revisited this, and I hadn't understood what you were achieving with the commenting-out of line 105 - after commenting out line 105, I needed to go back to Post Forms > Manage non-Toolset Fields, select 'Expiring Things' and make sure to add the expiration time.
For completeness, here is the sequence I have documented:
1. Comment out line 105 of Toolset Forms plugin file: cred-frontend-editor/library/toolset/cred/embedded/models/Fields.php
2. Go to Toolset > Post forms <scroll down to> 'Manage non-Toolset Post Fields with Toolset Forms' and select the button
3. Show fields for 'Expiring Thing' > Include Hidden Fields > +Add _cred_post_expiration_time as Date. It should look like the attached image.
4. Reactivate plugin line 105.

Now the _cred_post_expiration_time is available for use in Expiring Thing forms.
Sorted, thank you.

#2616599

My issue is resolved now. Thank you!