How to replace the hard-coded years string in the 1st line with the result of a function call?
Atm, the check is being done to see if there are any event posts whose event_date is matching the provided list items (like 2019, 2022) one by one. How to do the equivalent of
Where did you find this syntax? The way to display items in a list loop is with <Field /> without specifying a field name. This also means that your inner loop should be custom_field_value="{Field}".
I think you might simply be thinking about this the wrong way, which makes sense. You want to only display years if there’s an event within that year. But that doesn’t necessarily mean that the data related to your years needs to come from the custom field itself. Instead, you could loop through all years and then only display the year if there are posts that match that year. Same end result on the front end, but no need to build a list of specific years using data from some fields.
The way I’d achieve this would be this general structure (note that I haven’t tested this I’m just illustrating my idea as to how I’d structure this):