Elementor Posts Query: Upcoming Items by a Date Field
Adds a custom query ID "wpide_upcoming" that shows only items whose date field (for example an event date) is today or later, soonest first.
Opens WPIDE on
Code
// Custom field that holds the date, stored as Ymd.
$wpide_el_date_field = 'event_date';
add_action( 'elementor/query/wpide_upcoming', function ( $query ) use ( $wpide_el_date_field ) {
$meta_query = (array) $query->get( 'meta_query' );
$meta_query[] = array(
'key' => $wpide_el_date_field,
'value' => wp_date( 'Ymd' ),
'compare' => '>=',
'type' => 'NUMERIC',
);
$query->set( 'meta_query', $meta_query );
$query->set( 'meta_key', $wpide_el_date_field );
$query->set( 'orderby', 'meta_value_num' );
$query->set( 'order', 'ASC' );
} );
Notes
The field must store dates as Ymd (20261231), the ACF date picker default. Change the meta key to your field name.
How to add this snippet
- Install WPIDE on your WordPress site (it is free) and open Code Snippets.
- Use snippet above adds it from the library in one click. Or copy the code into a new snippet with the same code type.
- It is added inactive: review the code and settings, then switch it on.