18th Jul '22
/
20 comments

How to Show Future Events in Bricks

One of the common requirements in WordPress is being able to filter the events (or could be posts of any post type) to only those that are set to occur in the future via a custom fields plugin like ACF.

Here’s how future or upcoming events can be shown when using Bricks Builder.

Whether you are using the Posts element or the Query Loop feature, click the query (loop) icon and add a META QUERY like this:

where event_date is the name (when using ACF)/ID (when using Meta Box) of the date-type of custom field.

Meta value can be set to either

or

The Display and Return Formats for the field do not matter and can be set to any or left at their defaults.

Reference

https://forum.bricksbuilder.io/t/solved-post-loop-meta-query-by-acf-date-field/2309/9?u=sridhar

Get access to all 625 Bricks code tutorials with BricksLabs Pro

20 comments

  • Cees Coenen

    Hi Sridhar,

    I have follow this, I have follow tutorial from Tobias Haas... nothing works for me. Is there recently something changed?

    Cees

  • Great tips thanks, any idea how to only list events per venue in a list of upcoming events and past events please?

    • A

      Which events plugin are you using Rich?

      • Non, I've built it using ACF. I have posts set as ACF Events, and start_date_time to filter events so they are after todays date, but I can't get a filter/query to work so that it only shows events related to a venue. I've tried using ACF Relationship:Events as you can see on the bricks post here: https://forum.bricksbuilder.io/t/solved-post-loop-meta-query-by-acf-date-field/2309/11?u=sridhar

        • A

          How are the events tied to the venues? Relationship field or a custom taxonomy? If Relationship field, why not make it a taxonomy? It will be more performant plus easier to group events by their taxonomy.

          • Tied by a bi-directional relationship. I have events categorised by type (if that helps). Can you expand of the taxonomy option please? Thank you

            • A

              You could create a custom hierarchical (like categories) taxonomy called Event Venue for your Event CPT. Then in the event edit screen, select one or more venue(s) for each event.

              You can then either create multiple loops - one for each venue and in each taxonomy query loop, place another loop that outputs the venues in that taxonomy.

              The other option is to use code and do this automatically. See https://brickslabs.mystagingwebsite.com/posts-grouped-by-terms-in-bricks/.

              • Thanks, I've used the custom query code and a relation array to include venue too, no custom taxonomy needed. I then looked at what I had written: $args = [ 'post_type' => 'events', 'orderby' => 'meta_value', // We want to organize the events by date 'meta_key' => 'start_date_time', // Grab the "start date" field created via "ACF" (stored in YYYY-MM-DD format) 'order' => 'ASC', // DESC is the other option 'posts_per_page' => '-1', // Let's show them all. 'meta_query' => array( 'relation' => 'AND', array( 'key' => 'start_date_time', // Check the start date field 'value' => date("Y-m-d"), // Set today's date (note the similar format) 'compare' => '>=', // Return the ones greater than today's date 'type' => 'DATE' // Let WordPress know we're working with date ), array( 'key' => 'venue', // Check the venue field 'value' => '"' . get_the_ID() . '"', // matches exactly "123", not just 123. This prevents a match for "1234" 'compare' => 'LIKE' ) )

                ];

                And realising the relation venue needed the POST ID, i have it working without this custom code! HA. I will keep the code as I may need to use it again elsewhere, but i've worked out how to do this using the bricks options now. Thanks again, got there in the end

  • I'm using pods to build a custom event calendar. I've set up a query exactly like this but nothing displays when I set to "Greater Than"

    If I choose "lesser" the post will show the event with the second closest date in the future. Any ideas what I'm doing wrong?

  • Christian Strand

    Looks like my "timestamp code" actually outputted a php function here on your site

  • Christian Strand

    Hi. Using Metabox and I have my DateTime fields stored as timestamps so I can use the WordPress function to display the date in the correct language based on user. The above doesn't seem to work if I have "save as timestamp" selected in Metabox datetime field. Are you able to help witha filter that work based on timestamp rather than Ymd? I have tried to use 1773180383.

  • Perfect, works for Tribe Events Calendar as well! Thank you, I've been struggling on this one. :)

    • Michael van Dinther

      Hi Tilen,

      What Meta Key did you use for The Events Calendar

  • Can this also be achieved with a custom date field from JetEngine?

Leave your comment

 

Related Tutorials..

Pro
ACF Post Object Query Loop inside a Posts Query Loop in Bricks

ACF Post Object Query Loop inside a Posts Query Loop in Bricks

How to loop through a CPT and within each post, output a list of related posts.
Categories:
Pro
Nested Queries in Bricks – Posts Grouped by Published Years and Categories

Nested Queries in Bricks – Posts Grouped by Published Years and Categories

In the past we showed how posts could be grouped by years in Bricks. This Pro tutorial takes it further by grouping posts by categories…
Categories:
Pro
Post Titles and Post Content Tabs in Bricks

Post Titles and Post Content Tabs in Bricks

How to set up Nestable tabs with post titles as the tab menu, and post content and/or any other post-specific data as the tab content.
Categories:
Pro
How to Insert an Ad or an Element Between Posts in Bricks

How to Insert an Ad or an Element Between Posts in Bricks

How to insert an image or any Bricks element between posts output by a query loop.
Categories:
Tags:
Pro
Upcoming Events in Bricks Grouped by ‘Month Year’ with Frontend Filtering by Event Type

Upcoming Events in Bricks Grouped by ‘Month Year’ with Frontend Filtering by Event Type

Updated version of the earlier Upcoming Events Grouped by ‘Month Year’ in Bricks tutorial with some improvements:
Pro
Adjacent Posts Bricks Query Loop

Adjacent Posts Bricks Query Loop

This Pro tutorial provides the steps to customize a posts query loop in Bricks to show previous and next posts on single post pages. The…
Categories:
Pro
Custom SQL Ordering for Sorting Events in Bricks

Custom SQL Ordering for Sorting Events in Bricks

Showing events ordered by the event date with upcoming events in ascending order and past events in descending order.
Categories:
Pro
Hierarchical Posts with Nested Query Loops in Bricks

Hierarchical Posts with Nested Query Loops in Bricks

Learn how to set up nested query loops in Bricks to show hierarchical posts with child posts grouped under their corresponding parent posts
Categories: