Goal:
I would like to get only unique values from a loop.
For the moment, I have a loop that returns something like this:
2025 2025 2025 2025 2026 2026 2027 2027
and I would like to get only unique values:
2025 2026 2027
Or in other words, I need an equivalent of array_unique() function. Is there a filter for loops or anything else that could help me achieve it?
Context:
I want to create a simple filter for events (The Events Calendar) depending on a year. I have a loop that gets all the years of events:
<loop type="tribe_events" sort_field="_EventStartDate" sort_type="date" order="asc">
<field name="_EventStartDate" date_format="Y"></field>
</loop>
and below that, a filtered list of events with custom data attribute:
<loop type="tribe_events" sort_field="_EventStartDate" sort_type="date" order="asc">
<article data-year="{Field name='_EventStartDate' date_format='Y'}">
...
</article>
</loop>
In the first loop, I plan to add JS for showing or hiding events from the lower loop based on a year clicked.
Remarks:
- I use LiveCanvas which recommends html-like syntax with lowercase and explicit syntax when referencing fields.