I'm trying to make a View that displays posts that were published today.
I checked the Date Filters docuentation:
https://toolset.com/documentation/user-guides/date-filters/
There is a solution, but only for date custom fields created through Types. I want to do the same thing but on the post published date.
How to do that?
Dear Stanislav,
WordPress just introduced a new set of query arguments for filter by date. We will add date filter in next releases.
For now you can use this method:
Add this code to your theme/functions.php
add_filter( 'wpv_filter_query', 'wpv_show_today_posts' );
function wpv_show_today_posts( $query_args ) {
global $WP_Views;
if ( !is_admin() && isset($WP_Views->current_view) && $WP_Views->current_view == YOURVIEWID ) {
$query_args['date_query'] = array(
array(
'year' => date('Y'),
'month' => date('m'),
'day' => date('d'),
),
);
}
return $query_args;
}
Please let me know if you are satisfied with my answer and if I can help you with any other questions you might have.
Regards,
Gen.
Thanks Ghennadi,
As long as this makes it in the next version I am happy. 🙂