Skip Navigation

[Resolved] Limit views to display recent posts

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

Problem:

How to limit views on recent posts items for the last six (6) months?

Solution:

- Add the Query Filter.

- Select the custom field in question.

- Choose the item type to be NUMBER (Toolset saves dates as timestamp numbers).

- Select the BETWEEN conditional tag.

- For the first arm of the condition - the top one - add PAST_MONTH and set the number to 6.

- For the second arm of the condition - the bottom one - add TODAY.

date filter

The customer found out that using "PAST_DAY(183)" date function yields more accurate results.

Relevant Documentation:

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

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

This topic contains 6 replies, has 2 voices.

Last updated by Jane 2 years, 8 months ago.

Assisted by: Christopher Amirian.

Author
Posts
#2377413

How can I make a view display only posts from the past 6 months ?
From the current date and compared to a toolset date field, not the post date.

#2378247

Christopher Amirian
Supporter

Languages: English (English )

Screen Shot 2022-06-05 at 17.08.31.png

Hi there,

- Select the view block.
- On the sidebar scroll down to see the Contect Selection section.
- There you will see a section called Query Filters.
- Click the Add a Filter button and from the pop up select the custom field in question.
- Set the proper comparing operator. For example greater than or less than.
- The second option will have some DATE-related options, you can select for example TODAY option to compare, but you have other options if you need them.
- Click the Save button.

Thanks.

#2378311
Screenshot 2022-06-05 111354.png

Hi,
I have tried all kinds of combinations but I can not get it to work for between today & 6 months ago.
- greater than or lower than work fine, but that does not cover the date range.

What would be the best selection, or how would you set 6 months from the current date ?

No matter what I try i ether get nothing at all or everything.

#2378685

Christopher Amirian
Supporter

Languages: English (English )

Screen Shot 2022-06-06 at 11.47.06.png

Hi there,

You need to do as follows:

- Add the Query Filter.
- Select the custom field in question.
- Choose the item type to be NUMBER (Toolset saves dates as timestamp numbers).
- Select the BETWEEN conditional tag.
- For the first arm of the condition - the top one - add PAST_MONTH and set the number to 6.
- For the second arm of the condition - the bottom one - add TODAY.

Please check the attached screenshot.

The PAST_MONTH with 6 as the number will turn into a date function PAST_MONTH(6) which is what you want according to the documentation below:

https://toolset.com/documentation/user-guides/views/date-filters/#examples

That should do it.

Thanks.

#2378885

Better, but not perfect.

According to the documentation the PAST_MONTH(6) takes it back to the 1st of the month, not 6 months from the current date. So you could have some posts up to 7 months being shown, if the view was run at the end of a month.

#2378893

Christopher Amirian
Supporter

Languages: English (English )

Hi there,

There are other alternative date filters available in Toolset that you can check and see which one would yield the best result:

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

Thanks.

#2378895

I used PAST_DAY(183)

My issue is resolved now. Thank you!