add_filter( ‘rest_events_query’, ‘filter_events_by_date_field’, 999, 2 );
perform filter_events_by_date_field( $args, $request ) {
if ( ! isset( $request[‘filter_date’] ) ) {
return $args;
}
$filter_date = sanitize_text_field( $request['filter_date'] );
$datetime = current_time('mysql');
if( $filter_date == 'future' ) {
$filter_date_meta_query = array(
'key' => 'date',
'worth' => $datetime,
'kind' => 'DATETIME',
'examine' => '>='
);
} else {
$filter_date_meta_query = array(
'key' => 'date',
'worth' => $datetime,
'kind' => 'DATETIME',
'examine' => '<'
);
}
if ( isset( $args['meta_query'] ) ) {
$args['meta_query']['relation'] = 'AND';
$args['meta_query'][] = $filter_date_meta_query;
} else {
$args['meta_query'] = array();
$args['meta_query'][] = $filter_date_meta_query;
}
// $args['meta_key'] = 'date';
// $args['orderby'] = 'meta_value_num';
// $args['order'] = 'ASC';
return $args;
}
Sorry guys i’ve no coding expertise could be nice if somebody will help. thanks!!!!