Skip Navigation

[Resolved] How do filter posts by days old?

This support ticket is created 2 years, 2 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/Karachi (GMT+05:00)

This topic contains 1 reply, has 2 voices.

Last updated by Waqar 2 years, 2 months ago.

Assisted by: Waqar.

Author
Posts
#2290761

Tell us what you are trying to do?
I want to hide posts from a View that are 60 days old (based of publish date). How can I do this?

#2291643

Waqar
Supporter

Languages: English (English )

Timezone: Asia/Karachi (GMT+05:00)

Hi,

Thank you for contacting us and I'd be happy to assist.

To filter the view's results, where the published date falls within the last 60 days, you can use the 'wpv_filter_query', like this:


add_filter( 'wpv_filter_query', 'custom_date_filter_func', 1000 , 3 );
function custom_date_filter_func( $query_args, $view_settings ) {
	// process if specific view
	if ( ( isset($view_settings['view_id']) && $view_settings['view_id'] == 1234) ) {
		$query_args['date_query'] = array(
			array(
				'after' => '-60 days',
				'column' => 'post_date',
			)
		);
	}
	return $query_args;
}

Note: you'll replace '1234' with your actual view's ID.

Related links:
https://developer.wordpress.org/reference/classes/wp_query/#date-parameters
https://toolset.com/documentation/programmer-reference/views-filters/#wpv_filter_query

I hope this helps and please let me know if you need any further assistance around this.

regards,
Waqar

This ticket is now closed. If you're a WPML client and need related help, please open a new support ticket.