Skip Navigation

[Resolved] Filtering Views Query with past one year

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

Problem:
How to add a query filter to a view which shows posts with a custom date field value from the past year.
Solution:
When adding the query filter, values such as PAST_YEAR and PAST_MONTH will refer to the beginning of the period.

So comparing a date to PAST_YEAR = 2 would count back 2 years from the current date and rewind to January 1 of that year.

To go back exactly one year use PAST_DAY = 365.

Relevant Documentation:
https://toolset.com/documentation/user-guides/filtering-views-by-custom-fields/

This support ticket is created 7 years, 11 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+01:00)

Tagged: 

This topic contains 4 replies, has 2 voices.

Last updated by kelvinL-2 7 years, 11 months ago.

Assisted by: Nigel.

Author
Posts
#405799
Screen Shot 2016-06-09 at 7.52.29 PM.png

How can I query the post from today to past 1 year?

For example today is Jun 9, 2016, I only want to query all from Jun 10, 2015 to Jun 9, 2016.

I set the custom date field as number and range is greater than or equal the PAST_YEAR 1.

I have a post on 7 Jun 2015 but it also be filtered and show up.

What is the definition of PAST_YEAR when 1?

Best regards,

Kelvin;

#405819

Nigel
Supporter

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

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

Screen Shot 2016-06-09 at 15.57.56.png

Hi Kelvin

PAST_YEAR will go back a number of years but will start from 1 January.

If you want to go back one year from today use PAST_DAY with 365 instead.

(Sorry, leap years will drop a day.)

See the attachment.

#405839

Dear Nigel,

Do you mean the period of PAST_YEAR 1 mean 1 Jan 2015 to today not matter today is 1 Jan, 2016 or 31 Dec, 2016?

Best regards,

Kelvin.

#405845

Nigel
Supporter

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

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

Yes, that's right.

For any date in 2016, PAST_YEAR 1 means 1 January 2015.

I haven't checked, but I think PAST_MONTH 12 would mean the 1st day of the month which is 12 months ago if that makes sense, which is why I suggested PAST_DAY 365.

#406069

Noted with thanks!

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