Opens in a new tab
5th Apr '23
/
0 comments

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: eventDate 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 633 Bricks code tutorials with BricksLabs Pro

Related Tutorials..

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
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:
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
Non-empty events sorted by event date and other posts below in Bricks

Non-empty events sorted by event date and other posts below in Bricks

Updated on 15 Jan 2024 Consider a scenario where you are showing posts from multiple post types namely post, event and game in a single…
Categories:
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.
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: