Skip Navigation

[Resolved] View Filter by Date

This support ticket is created 6 years, 7 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)

Tagged: 

This topic contains 1 reply, has 2 voices.

Last updated by Luo Yang 6 years, 7 months ago.

Assisted by: Luo Yang.

Author
Posts
#668651

Hi!
I need set a date filter in a view, to show items with published date in the last two days. How can i do this?

#670749

Hello,

You can setup such a filter with Views hook "wpv_filter_query", for example, add below codes into your theme/functions.php:

add_filter( 'wpv_filter_query', 'my_date_func', 99, 3 );
function my_date_func( $query, $settings, $view_id ) {
    if ( $view_id == 123) {
        $query['date_query'] = array(
			array(
				'column' => 'post_date_gmt',
				'after' => '2 days ago',
			),
		);
    }
    return $query;
}

Please replace 123 with your view's ID

More help:
https://codex.wordpress.org/Class_Reference/WP_Query#Date_Parameters