Skip Navigation

[Resolved] Filter views by date

This support ticket is created 3 years, 4 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
- 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 -
- 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 -

Supporter timezone: Asia/Hong_Kong (GMT+08:00)

This topic contains 8 replies, has 2 voices.

Last updated by michaelM-30 3 years, 4 months ago.

Assisted by: Luo Yang.

Author
Posts
#2103627

I would like to generate a slider or a view in order to show posts that occured exactly one year ago, or 50 years ago to the exact date like today.

Let's say today is July 1. 2021

I would like to show posts from July 1. 2020
and lets say posts from July 1. 1990 or July 1. 1970.

We have lots of old pictures and it would be nice to have a feature like in google photos, where you see images/posts that were in the past, but exactly this to the current day.

I was looking at your documentation here:
https://toolset.com/documentation/user-guides/views/filtering-views-query-by-date/

#2103673

Hello,

There isn't such kind of built-in feature within Toolset plugins, but you can try the workaround mentioned in below thread:
https://toolset.com/forums/topic/how-to-add-month-and-year-dropdown-filters-for-an-archive-search/#post-1236133

#2103683

Hello Lou,
sorry but this isn't what I was looking for. I do not need a dropdown with certain dates or years.
What I need is the exact date of the current day back in time - x years ago, showing me the posts.

#2103699
date-filter2.JPG

You can setup the Post date filter in view's query, like this:
Select posts whose
Published date is after: year:VIEW_PARAM(year), month:VIEW_PARAM(month)
See my screenshot date-filter2.JPG

And display above view's shortcode with "year" and "month" attributes, for example:
[wpv-view name="your-view-slug" year="2020" month="6"]

#2103725

With your setup I can select a SPECIFIC date in time and dispay the posts befor or after etc.
But what I need is a way to tell the system to calculate this date to be lets say 40 years from TODAY (for every day, so tomorrow it will be July 2nd , then July 3rd etc.) but 40 years ago.

#2103727

For the new question, it needs custom codes, for example, you can try these:
1) Add below codes into your theme file "functions.php":

add_shortcode('time-ago', function ($atts = [], $content = null) {
     
    return human_time_diff( wpv_do_shortcode($content) );
 
});

2) Use above shortcode like this:
[time-ago][wpv-post-date format="U"][/time-ago]

More help:
https://developer.wordpress.org/reference/functions/human_time_diff/

#2103761

It seems I cannot see your last reply here in the ticket. (I copied your reply below)
I only see an excerpt sent via email.

Sorry I am no programmer, how would I use the function in order to display e.g. posts that are one year ago on this exact day?
with this shortcode?
[time-ago][wpv-post-date format="U"][/time-ago]

For the new question, it needs custom codes, for example, you can try these:
1) Add below codes into your theme file "functions.php":

add_shortcode('time-ago', function ($atts = [], $content = null) {

return human_time_diff( wpv_do_shortcode($content) );

});

2) Use above shortcode like this:
[time-ago][wpv-post-date format="U"][/time-ago]

More help:
https://developer.wordpress.org/reference/functions/human_time_diff/

#2104421

Please provide a test site with the same problem, fill below private message box with your website credentials, also point out the problem page URLs and view URL, I can setup a demo for you.

#2104537

Thank you I found what I needed - it's working.
My issue is resolved now. Thank you!