Event and Location Grouping and Ordering
A list of upcoming events can get repetitive. A weekly class fills the page with the same title, and a busy venue pushes everything else down. The groupby attributes fix that by showing one item per group: the next date of each recurring event, the next event at each location, one location per country.
They work in [events_list], [locations_list], the other list and map shortcodes, and the matching PHP functions.
This page is about collapsing a list to one item per group. To print events under date headings ("November 2026", "December 2026"), use [events_list_grouped]. To filter by category or tag, use the category and tag attributes.
The three attributes
| Attribute | Default | What it does |
|---|---|---|
groupby | none | The field to group by. Items with the same value in this field form a group, and only one of them is shown. |
groupby_orderby | event_start_date,event_start_time for events, location_name for locations | The fields that decide which item of each group is shown: the group is sorted by these, and the first one wins. |
groupby_order | ASC | ASC picks the first item of each group in that sort (the earliest event), DESC the last (the latest event). |
groupby takes one field name: a column of the events table (wp_em_events) or the locations table (wp_em_locations). The ones used most:
| Field | Groups by |
|---|---|
recurrence_set_id | Recurring event. Every date of one recurring event shares this value. |
location_id | Location. |
event_owner | The user who owns the event. |
blog_id | Site, on a multisite network with global tables. |
location_town, location_state, location_region, location_country | Part of the location's address. Reliable in [locations_list]. See Limits before using these in an events list. |
An item that has no value in the grouping field is not grouped at all, and is listed on its own. Group events by location_id, and every event without a location still appears. Group by recurrence_set_id, and every one-off event still appears. That is usually what you want.
Grouping and ordering are separate
Two different sorts are at work, and mixing them up is the usual cause of confusion:
groupby_orderbyandgroupby_orderwork inside each group, and decide which single item represents it.orderbyandordersort the final list, after one item per group has been chosen.
scope and the other filters are applied first, so "the earliest event in the group" means the earliest one that matches the rest of the shortcode. With the default scope of future events, that is the next upcoming event.
A worked example
The demo site has ten events. Sunrise Beach Yoga repeats every Saturday at Maple Bay Pier, two events are at Lighthouse Park, and one webinar has no physical location. This shortcode shows the next event at each location, with the final list in alphabetical order:
[events_list groupby="location_id" orderby="event_name" order="ASC"]
| What happens | Result |
|---|---|
| Events are filtered | Upcoming events only, because scope defaults to future. |
Events are grouped by location_id | Five groups, one per location, plus the webinar, which has no location and stays on its own. |
Each group is sorted by start date and time, ascending (the default groupby_orderby) and the first is kept | Maple Bay Pier keeps the next Sunrise Beach Yoga. Lighthouse Park keeps Lighthouse Park Sunset Flow and drops Family Movie Night in the Park, which is later. |
The six survivors are sorted by event_name | Farmers Market Cooking Class, Harbor Lights Jazz Night, Lighthouse Park Sunset Flow, Small Business Marketing Webinar, Sunrise Beach Yoga, Watercolor Workshop for Beginners. |
Change groupby_order to DESC and each location shows its last upcoming event instead: Lighthouse Park would show Family Movie Night in the Park.
To leave out events that have no location, add has_location="1".
In PHP the same list is:
echo EM_Events::output( array(
'groupby' => 'location_id',
'orderby' => 'event_name',
'order' => 'ASC',
) );
Recipes
Show each recurring event once
[events_list groupby="recurrence_set_id"]
Every one-off event is listed, and each recurring event appears once, on its next date.
Use recurrence_set_id for this. Older tutorials use recurrence_id, which the dates of a recurring event created in Events Manager 7 no longer carry, so it leaves the list unchanged.
To hide the dates of recurring events altogether, use recurrences="0" instead.
The next event at each location
[events_list groupby="location_id" has_location="1"]
The last event of the year at each location
[events_list scope="2026-01-01,2026-12-31" groupby="location_id" groupby_order="DESC"]
One location per country, first by name
[locations_list groupby="location_country" groupby_orderby="location_name" orderby="location_country"]
One venue per country, with its upcoming events
A list of locations can print each location's events with a placeholder, so grouping locations and listing events combine:
[locations_list eventful="1" scope="future" groupby="location_country" groupby_orderby="location_name"]
<h3>#_LOCATIONNAME</h3>
#_LOCATIONNEXTEVENTS
[/locations_list]
The next event on each site of a network
On a multisite network with global tables enabled, run this on the main site:
[events_list groupby="blog_id"]<p>#_EVENTLINK, #_EVENTDATES</p>[/events_list]
When grouping is the wrong tool
Grouping always reduces a group to one item. If you want every location as a heading with all of its upcoming events underneath, list the locations and let a placeholder print the events:
[locations_list eventful="1" scope="future"]
<h3>#_LOCATIONNAME</h3>
#_LOCATIONNEXTEVENTS
[/locations_list]
The same works for categories with [categories_list] and #_CATEGORYNEXTEVENTS, and for tags with [tags_list] and #_TAGNEXTEVENTS.
Limits
- One field.
groupbyuses the first field you give it. A comma-separated list is not combined. - Field names must be exact. A name that is not a column of the events or locations table is ignored, and the list comes out ungrouped.
- Location fields in an events list. Grouping events by a field of the locations table, such as
groupby="location_town", can return more than one event for the same value in Events Manager 7.5, depending on your database server. Group bylocation_idwhere you can, or group a[locations_list]by that field.
Troubleshooting
Nothing changes when I add groupby
Check the field name. location, recurrence and town are not field names, location_id, recurrence_set_id and location_town are. For recurring events, use recurrence_set_id.
The wrong event is shown for each group
The event shown is the first one in the groupby_orderby sort, inside your scope. For the next upcoming event, keep scope="future", groupby_orderby="event_start_date,event_start_time" and groupby_order="ASC", which are the defaults, and check that Default List Scope in Events then Settings then General then General Options has not been changed to include past events.
The list is in a strange order
groupby_orderby does not sort the final list. Add orderby and order for that, for example orderby="event_start_date,event_start_time".