Events Grouped by Event Year

In this Pro tutorial, we share the PHP code for outputting past events grouped by the event year in descending order of the event year.

Scenario:

CPT: event
Date custom field: event_date

Sample events:

Current date at the time of writing this tutorial: 5 Apr 2023

Output:

We shall

  • get all the past events using get_posts() and a meta_query
  • loop through the past events and store them as values of an array whose keys are the years
  • sort years in descending order
  • loop through the years and output the events grouped by years

Note: This code can be used in any WordPress site and is not Bricks-specific.

PHP

This is a BricksLabs Pro tutorial.

For full access login below or create your BricksLabs Pro account

Get access to all 526 Bricks code tutorials with BricksLabs Pro

Related Tutorials..

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
ACF Relationship: Show all other events related to the artists of the current event

ACF Relationship: Show all other events related to the artists of the current event

How all other events related to the artists of the current event can be output in a Bricks query loop.
Categories:
Pro
Modern Events Calendar in Bricks

Modern Events Calendar in Bricks

This Pro tutorial provides the steps for using Modern Events Calendar in Bricks. We shall set up the single event Bricks template with a combination…
How to Show Future Events in Bricks

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…
Categories:
Pro
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

How to output events grouped by years and months using three nested query loops in Bricks.
Categories:
Pro
Events grouped by Event Date custom field in Bricks

Events grouped by Event Date custom field in Bricks

This Pro tutorial for Bricks users provides the steps to output posts of an event custom post type dynamically grouped by the value of their…
Categories:
Pro
Single Event Template for The Events Calendar in Bricks

Single Event Template for The Events Calendar in Bricks

Updated on 19 Sep 2024 The Events Calendar is one of the most popular event plugins for WordPress. With The Events Calendar active, single event…
Pro
Upcoming Events Grouped by ‘Month Year’ in Bricks

Upcoming Events Grouped by ‘Month Year’ in Bricks

A custom query loop type for showing future events based on a date custom field using three nested query loops.