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:

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