1

I have three channels: Events, stages and artists.

An artist is added to a timetable super table field in the stage channel. In the event, I have a stages field where I select stages. Events also have a category field.

So: Event ---> stage --(ST field)--> artists.

I basically need two queries for now:

1.- In a filter page, I'd like to display the artists based on a category through events.

2.- In the artist profile, I'd like to show all the events he/she plays.

This is what I have so far, but I feel I could be waaay more efficient, at least the first one, cause the 2nd one I think is not that bad:

1.

// Artists for category through events

{% set category = craft.categories.slug('rock').one() %}

{% set events = craft.entries.section('event').with('stages.timetable.artists').relatedTo(category).all() %}

{% for event in events %}
    {% for stage in event.stages %}
        {% for timeslot in stage.timetable %}
            {% for person in timeslot.artistsSpeakers %}
                {{ person }}
            {% endfor %}
        {% endfor %}
    {% endfor %}
{% endfor %}

2.

// Events of an artist

{% set artist = craft.entries.section('artists').one() %} {# Any artist #}

{% set stages = craft.superTable.getRelatedElements({
  relatedTo: {
    targetElement: artist,
    field: 'timetable.artists'
  },
  section: 'stages'
}) %}

{% set events = craft.entries.section('events').relatedTo(stages).all() %}

{% for event in events %}
  {{ event.title }}
{% endfor %}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.