# Bricks Query Loop: Upcoming Items by a Date Field

> Limits the chosen Bricks query loops to items whose date field is today or later and sorts them soonest first, for event and webinar lists.

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

## Code

```php
// Query loop element IDs and the date field (stored as Ymd).
$wpide_bricks_upcoming_ids  = array( 'abcdef' );
$wpide_bricks_upcoming_meta = 'event_date';

add_filter( 'bricks/posts/query_vars', function ( $query_vars, $settings, $element_id ) use ( $wpide_bricks_upcoming_ids, $wpide_bricks_upcoming_meta ) {
    if ( ! in_array( $element_id, $wpide_bricks_upcoming_ids, true ) ) {
        return $query_vars;
    }

    $meta_query   = isset( $query_vars['meta_query'] ) ? (array) $query_vars['meta_query'] : array();
    $meta_query[] = array(
        'key'     => $wpide_bricks_upcoming_meta,
        'value'   => wp_date( 'Ymd' ),
        'compare' => '>=',
        'type'    => 'NUMERIC',
    );

    $query_vars['meta_query'] = $meta_query;
    $query_vars['meta_key']   = $wpide_bricks_upcoming_meta;
    $query_vars['orderby']    = 'meta_value_num';
    $query_vars['order']      = 'ASC';

    return $query_vars;
}, 10, 3 );
```

## Notes

The date field must store Ymd values (ACF date picker default). Set the element IDs and field name at the top.

## How to use it

Install the free WPIDE plugin (https://wordpress.org/plugins/wpide/), find "Bricks Query Loop: 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/
