Skip Navigation

[Resolved] How to add a date filter to a View

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

Problem:
Client has added a date field to posts, and wants to display only posts with future dates in a View.

Solution:
When filtering by date and comparing to TODAY(), it must be remembered that date fields are stored as UNIX timestamps, i.e. as numbers, and so the comparison chosen for the filter should be as a NUMBER.

Relevant Documentation:
https://toolset.com/documentation/user-guides/date-filters/

This support ticket is created 6 years, 3 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
- 7:00 – 14:00 7:00 – 14:00 7:00 – 14:00 7:00 – 14:00 7:00 – 14:00 -
- 15:00 – 16:00 15:00 – 16:00 15:00 – 16:00 15:00 – 16:00 15:00 – 16:00 -

Supporter timezone: Europe/London (GMT+00:00)

Tagged: 

This topic contains 4 replies, has 2 voices.

Last updated by larryB-3 6 years, 3 months ago.

Assisted by: Nigel.

Author
Posts
#1076238

Tell us what you are trying to do? I would like to create a CPT for Alerts. My CPT would just contain a few fields, one of them being a date to expire the CPT. For example, I would have an Alert that would appear for 4 days and expire on 08/09/2018. I would create a view that would show any alerts that have not expired on my home page. Is there a way to do this with Toolset?

#1076256

Nigel
Supporter

Languages: English (English ) Spanish (Español )

Timezone: Europe/London (GMT+00:00)

Hi Larry

If you add Alert posts from the front-end using Toolset Forms, then yes, you can use the post expiration feature.

See the documentation here: https://toolset.com/documentation/user-guides/automatic-post-expiration/

However, that involves giving all posts created with the form the same expiration period (e.g. after 4 days), though you can modify this on a post-by-post basis using the Forms API.

But if you are displaying the Alerts with a View you don't really need this.

Just add your field for the date/time when the Alert post should "expire".

Then create a View to show unexpired Alerts which has a Query Filter for that expiry date field to only show posts with an expiry date after NOW(). (See https://toolset.com/documentation/user-guides/date-filters/)

Unlike the Forms post expiration feature, which changes the status of posts from published, you will simply not be listing the expired Alert posts, even though they are still published.

#1076573
Screen Shot 2018-08-07 at 7.41.44 PM.png

Thanks, but I'm stuck. Nothing gets returned when I have an alert with expires date set to tomorrow. I tried greater than and lower than, both returned nothing.

#1077288

Nigel
Supporter

Languages: English (English ) Spanish (Español )

Timezone: Europe/London (GMT+00:00)

Hi Larry.

Types date fields are stored as UNIX timestamps, meaning they are NUMBERS, not DATES.

If you change the type to NUMBER it should work okay.

#1077553

Thanks! That worked!