Home › Toolset Professional Support › [Resolved] Hide date in frontend after reaching that date
Problem: I have a custom post type "Training Module" that occurs on multiple dates. I would like to show all the upcoming dates for the Training Module and hide all the past dates.
Solution: Create a new custom post type called "ModuleOnDate" or something similar. Set this post type to be a child of the Training Module post type. Create a View of ModuleOnDate posts, filtered by post relationship, where the parent is set by the current page. Add a custom field date filter, where the custom field value is an UNSIGNED value greater than or equal to TODAY. Insert the custom field date into the Loop Output using the Fields and Views button.
Insert the View of ModuleOnDate posts into the Training Module post's Content Template or Template Layout.
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 | 14:00 – 18:00 | 13:00 – 18:00 | - |
Supporter timezone: America/Jamaica (GMT-05:00)
Tagged: Setting up custom fields, Types plugin
Related documentation:
This topic contains 4 replies, has 3 voices.
Last updated by marcialB 6 years, 7 months ago.
Assisted by: Shane.
- Tell us what you are trying to do?
Hi there, we use your solution to display training modules. Each of them have dates to show when they happen the next time. We would like to hide the dates that have passed. Currently we would have to edit the posts everytime there is a training, delete the current date and add one at the end of the list (we would like to display 3-4 upcoming dates). I was hoping there was an option to set like 10 upcoming dates, and in the frontend it only displays the next 3 dates. Each time the page loads, it should check if a date has passed and if so, it doesn't show the date and uses the next ones instead.
Is this something we can achieve with the conditional statements? Or is there another solution?
- Is there any documentation that you are following?
No, I dind't find anything about that.
- Is there a similar example that we can see?
It's kind of what most event plugins are doing, except that in our case the page itself stays online. Also there is no calendar or a list of upcoming events.
- What is the link to your site?
Not yet finished.
-----
Thanks for your help!
Best,
Marcial
Hi, at first glance this seems like it could be accomplished with a repeating date field. The wpv-for-each shortcode can be used to loop over all the instances of a repeating field, but the problem is it's not possible to use conditionals in a wpv-for-each. So I don't think that will work here. Instead, another option is to create a new custom post type like "ModuleOnDate" that stores the date in a custom field. Set that custom post type to be a child of the training module post type, and add ModuleOnDate child posts to each Module. Insert a View of ModuleOnDate posts, with a post relationship filter, set by the current page, and a custom field date filter where the date is greater than or equal to TODAY().
Let me know if you have questions about that.
Hi Christian
Thanks for your response. That sounds very good. I'll try that and let you know if I managed to get it to work.
Best,
Marcial
Hi Marcial,
As Christian is currently on vacation I will be handling this ticket, is there any update on this one ?
Thanks,
Shane
Hi Shane
You guys are awesome! It works. It took me a while until I figured out that I have to use "UNSIGNED" instead of "DATE", but now it works.
I even managed to get the
format='l, j. F Y'
to show the way I want it.
Thanks again.
Best,
Marcial