# 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.

- Type: PHP
- Runs: Run everywhere
- Category: [Page Builders & Themes](https://wpide.com/library/category/page-builders/)
- Tags: elementor, query, events, custom-fields
- Author: WPIDE Team
- Installs: 0
- Updated: 2026-10-28
- Page: https://wpide.com/library/elementor-query-upcoming-by-date-field/

## Code

```php
// 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 use it

Install the free WPIDE plugin (https://wordpress.org/plugins/wpide/), find "Elementor Posts Query: Upcoming Items by a Date Field" in its snippet library and add it in one click; or create a new PHP snippet in WPIDE (or any code snippets plugin) and paste the code above. More snippets: https://wpide.com/library/
