1

I'm having a little trouble wrapping my head around Relations through a Matrix field.

I have a Structure called exhibitors.

I have a Matrix field on a Page called rooms, This has one block type room and within that block there is an entries relationship field called exhibitors.

What I'm wanting to do is loop through the exhibitor entries and for each one, I want to find the first room they are related to via the matrix field.

I've tried various flavours of the relatedTo method, but I just can't seem to get them related, I just get null back from every one I've tried.

Here's an example of one I've tried:

{% set exhibitors = craft.entries.section('exhibitors').order('title') %}

{% for exhibitor in exhibitors %}
    {% set room = entry.rooms.relatedTo({
        sourceElement: exhibitor,
        field: 'room.exhibitors'
    }).first() %}

{{ room }} <-- Always a null entry

{% endfor %}
1

So, it looks as though I was overcomplicating things! All it needs to be is this:

{% set exhibitors = craft.entries.section('exhibitors').order('title') %}

{% for exhibitor in exhibitors %}
    {% set room = entry.rooms.relatedTo(exhibitor).first() %} 

    {{ room }} <-- No longer a null entry

{% endfor %}

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.