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
December 29, 2024 at 3:58 pm
#52367
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;
});