8th Mar '24
/
17 comments

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

Events grouped by months within years 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 and inside the 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

Get access to all 630 Bricks code tutorials with BricksLabs Pro

Related Tutorials..

Pro
Related Posts by Taxonomy in Bricks

Related Posts by Taxonomy in Bricks

In the previous Posts Related by Current Post's Terms in Bricks tutorial, we showed how posts related to the current single post that have the…
Categories:
Pro
Recently Viewed Posts Bricks Query Loop

Recently Viewed Posts Bricks Query Loop

How to output the most recent X number of posts (any post type) viewed by the current visitor.
Categories:
Related Posts by Author in Bricks

Related Posts by Author in Bricks

Querying posts on single posts by the author of the current post.
Categories:
Pro
How to Query WordPress Taxonomy Terms by Hierarchy Level in Bricks

How to Query WordPress Taxonomy Terms by Hierarchy Level in Bricks

How to limit the terms of a Bricks Terms query to only those at a specific level within the taxonomy hierarchy.
Categories:
Pro
Posts older than today in Bricks

Posts older than today in Bricks

How to display only posts that were published before today in a query loop.
Categories:
How to List Your Posts Divided by Categories in Bricks

How to List Your Posts Divided by Categories in Bricks

In this tutorial, we'll learn how to display a list of posts divided by each category. The DOM tree Here is how I structured my…
Categories:
Pro
Posts Grouped by Years and Months in Bricks

Posts Grouped by Years and Months in Bricks

How display posts organized by months & within years based on the published date.
Categories: