Skip Navigation

[Resolved] Using Date Filters to show posts from the past 30 days

This support ticket is created 3 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.

No supporters are available to work today on Toolset forum. Feel free to create tickets and we will handle it as soon as we are online. Thank you for your understanding.

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: Africa/Casablanca (GMT+01:00)

This topic contains 4 replies, has 2 voices.

Last updated by Timothy 3 years, 3 months ago.

Assisted by: Jamal.

Author
Posts
#2147847

Hi,

I'm trying to use the Post Date Filter to show posts from the past 30 days. I would think if I choose "Published Date" is "after or equal to" Month "Past_One" 0 should work. But it seems to only show those from this current month. I also tried Day "Past_One" 30, that doesn't work either. What am I missing?

Tim

#2148857

Hello Tim and thank you for contacting Toolset support.

Can you try again by setting past year to 0, past month to 1, and past day to 30. Like this screenshot hidden link

You can also do it with custom code. Add and adapt the following code, based on the view's ID(change 1234 with the view's ID), to a Toolset snippet:

add_filter( 'wpv_filter_query', 'get_past_thirty_days_posts', 10, 3);
function get_past_thirty_days_posts( $query_args ,$view_settings, $view_id ) {
    if ( $view_id == 1234) {
        $query_args['date_query'] = array(
            'column' => 'post_date',
            'before'  => '30 days ago',
        );
    }
    return $query_args;
}

Check this article on how to add custom code to a Toolset snippet https://toolset.com/documentation/programmer-reference/adding-custom-code/using-toolset-to-add-custom-code/

I hope this helps. Let me know if you have any questions.

#2148917

Excellent, this works. But can you explain to me why this works? I would just like to understand how this Date filter works in case I need to use it in another fashion.

Tim

#2149509

Hello Tim, we have old documentation about the date filters on the following articles, but we have also reports of some bugs, the behavior of the filters is not exactly the same as the documentation. And our developers are working on a revamp of the date filters to make them more natural to use:
- https://toolset.com/documentation/user-guides/views/date-filters/
- https://toolset.com/documentation/user-guides/views/filtering-views-query-by-date/

Honestly, I have activated the view's debug popup(Toolset->Settings->Front-end Content) and I was testing the various possibilities and checking what is the underlying SQL query behind it.
If I set only days, then it searches by the day of the month, if I set only the month, it searches for posts that are in the next months even in previous years, then I was able to set it using the 3 or them(year, month, day). I did not try to use a negative value for days(Future_day(-30)).

#2149945

My issue is resolved now. Thank you!