13th May '25
/
1 comment

Upcoming Events with ACF Date Sub field Repeaters grouped by Month Years in Bricks

In the comments section of Upcoming Events Accordion in Bricks Grouped by 'Month Year' a member asked:

CPT: eventACF Field: event_dates (Repeater) with event_date sub field

Sample data:

After implementing the tutorial, the output with Bricks elements for the month years, event titles and dates using nested query loops:

This Pro tutorial provides the steps to

  • add a custom query type called 'Month Years' to Bricks control options
  • configure how the query runs by checking for our custom query type
  • query and retrieve all event posts
  • process each event's dates using ACF repeater fields
  • filter out past events, keeping only future dates
  • format each event's date information (day, month, year, weekday)
  • sort all events chronologically
  • group events by month and year
  • create a helper function to handle Bricks loop objects
  • build a function to retrieve specific event values (day, month, year, weekday) by Bricks ID
  • and use these to set up nested query loops for outputting the data in the desired format

Step 1

If you have not already, create the CPT and the field group.

Ensure that the return format of the date field is Ymd.

Create event posts and set all the dates on which each event is set to occur.

Step 2

Add the following in child theme's functions.php (w/o the opening PHP tag) or a code snippets plugin:

This is a BricksLabs Pro tutorial.

For full access login below or create your BricksLabs Pro account

Get access to all 610 Bricks code tutorials with BricksLabs Pro

Related Tutorials..

Pro
Excluding Duplicate Posts from Query Loops in Bricks

Excluding Duplicate Posts from Query Loops in Bricks

How to ensure that posts are not duplicated when two query loops are used on the same page.
Categories:
Pro
Post-specific ACF Repeater Galleries as Sliders in Bricks

Post-specific ACF Repeater Galleries as Sliders in Bricks

How to output ACF Repeater field rows with the images of the Gallery-type sub field as a slider.
Pro
Posts from Random Categories in Bricks

Posts from Random Categories in Bricks

Updated on 31 Jul 2023 In BricksLabs Facebook group a user asked: How would you query 3 WordPress posts from 3 different categories with Brick…
Adding any Custom WP_Query loop to Bricks’ Query Loop

Adding any Custom WP_Query loop to Bricks’ Query Loop

Sometimes we may need to create a custom post loop using Bricks' query loop feature, but wish to use our own WP_Query code for more…
Pro
Ordering Posts by Terms in Bricks

Ordering Posts by Terms in Bricks

How to output upcoming events at the top and past events below in a single query loop in Bricks.
Categories:
Posts Related by Current Post’s Terms in Bricks

Posts Related by Current Post’s Terms in Bricks

Showing other posts assigned to the same categories/tags/custom taxonomy terms as the current post.
Categories:
Pro
Filtering posts by a group field’s subfield value with Meta Box when using a custom table in Bricks

Filtering posts by a group field’s subfield value with Meta Box when using a custom table in Bricks

Filtering a query loop to output only those posts with the value of a Select subfield of a Group field set to Yes when using…
Categories:
Tags: