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.
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.
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.
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.
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.
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.
I used PAST_DAY(183)
My issue is resolved now. Thank you!