This website uses cookies to personalize your experience. By using this website you agree to our cookie policy.

Reply To: Date Filter: Who is working today

Home Forums Product Support Forums Ajax Search Pro for WordPress Support Date Filter: Who is working today Reply To: Date Filter: Who is working today

#52367
Ernest MarcinkoErnest Marcinko
Keymaster

Pefrect!

I have managed to put together a fairly tiny code snippet, which seems to be working. I have placed it into the code snippet plugin you are using under the name “Ajax Search Pro – Today filter”.

I have also changed the filter to a radio button, with a yes/no option. When “Yes” is clicked, then only results matching todays date should be displayed.

For future reference, here is the custom code, it turned out to be only a few lines:

add_filter('asp_query_args', function($args){
	foreach ( $args['post_meta_filter'] as $k => &$filter ) {
		if ( $filter['key'] !== 'days_worked' ) {
			continue;
		}
		if ( $filter['value'] === 'no' ) {
			unset($args['post_meta_filter'][$k]);
		}
		$filter['value'] = date('Y-m-d');
	}
	
	return $args;
});