filter by meta_key date field > now
-
Hi,
I know this has been asked, but I can’t actually find the solution anywhere. In the meta query builder, how do I filter for dates that have gone past/equal to now/today?
eg (for a CPT called event, and acf field called ‘event_start_time’ with normal date format eg 2026-02-27 17:16:18)
meta_key = ‘event_start_time’
meta_value = ???
meta_compare = > (or >=?)
meta_type = DATETIMEHow do I put ‘now’ or todays date into ‘meta_value’ box?
I’ve tried:now(), date(), todays_date, date(“Y-m-d H:i:s”)
It works fine with an actual date – 2026-02-27 17:16:18Similarly how would I write for between? eg [now, now + 1 year).
thanks,
Simon
-
Yes please can someone explain this, i also can’t find solution, but seems like something this tool would be able to do?
So the answer was adding this snippet to define Today’s date in a way that can be accessed in the block
function change_query_date_value( $query_args, $block_query, $inherited ) {
if ( isset( $query_args['meta_query'] ) && ! empty( $query_args['meta_query'] ) ) {
if ( $query_args['meta_query'][0]['value'] == 'todays_date' ) { $query_args['meta_query'][0]['value'] = date('Ymd'); }
}
return $query_args;
}
add_filter( 'aql_query_vars', 'change_query_date_value', 10, 3 );Then using AQL’s meta query builder to compare to todays_date variable

Ah, I think I saw that, but wasn’t sure how to use it so went right past it!
thanks,
Simon
This is a great approach! I am working on adding some native ways to define dynamic items like todays date, current user, current post etc etc but in the meantime this will work really well.
You must be logged in to reply to this topic.