Events grouped by years within months based on event date custom field value

Updated on 17 Apr 2024

This Pro tutorial provides the steps to output posts of an event custom post type grouped by years within months based on the event's event_date custom field value using three nested query loops in Bricks.

This is an advanced usage showcase of Bricks' querying capabilities and PHP arrays.

We are going to set up a custom "Event Years" query type loop, output the year, inside that a custom "Event Months" query type loop and inside that a Posts query loop that pulls in the current looping year and month's posts.

Step 1

Create an event CPT.

Create a field group for this CPT having a date-type of field called event_date.

Step 2

Add some events and populate the event date field.

Step 3

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

Instant access to 390+ Bricks code tutorials with BricksLabs Pro