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
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.
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
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)).
My issue is resolved now. Thank you!