<p>The <code>relatedTo</code> parameter can take an object, an element ID or an array of element objects and/or IDs. In your case the latter is expected so wrapping your arguments in an array should fix the issue:</p>

<pre class="lang-twig prettyprint-override"><code>{% set entries = craft
                .entries
                .section('survivorAssets')
                .relatedTo(['and',{ targetElement: theme },{ targetElement: survivor }])
                .orderBy('assetOrder')
                .all() %}
</code></pre>

CC BY-SA 4.0
2020-01-28T09:24:09.117Z
2020-01-28T09:24:09.117Z
Oli
<p>I'm having trouble setting entries with multiple relations.</p>
<p>during testing I've hard coded the theme to 1 specific category</p>
<pre><code>{% set themeID = &quot;12309&quot; %}
{% set theme = craft.categories.group('survivorThemes').id(themeID).all() %}
</code></pre>
<p>I then set this</p>
<p><code>{% set survivors = craft.entries.section('authors').includeInRecollection('1').relatedTo({ sourceElement: relatedAssetIds }).orderBy('lastName asc').limit(null).all() %}  </code></p>
<p>and then a for loop</p>
<pre><code>        {% for survivor in survivors %}
            {% set relatedIds = &quot;&quot; %}






{# this should work but doesn't #}
            {% set entries = 
                craft.entries.section('survivorAssets')
                .relatedTo('and', { targetElement: themeID },{ targetElement: survivor })
                .orderBy('assetOrder')
                .all() 
            %}  

{# this should also work but doesn't #}
            {% set testEntries = craft.entries.section('survivorAssets')
                .relatedTo('and', {targetElement: survivor, field: 'relatedSurvivor'}, {targetElement: themeID, field: 'themes'})
                .orderBy('assetOrder')
                .all()  %}






          &lt;div class=&quot;testing&quot; style=&quot;background:red;color:#fff;padding:30px;margin:30px;&quot;&gt;

            survivor: {{ survivor.title }} &lt;br&gt;

            theme: {{ themeID }} &lt;br&gt;

            ids: {{ relatedIds}} &lt;br&gt;

            total results: {{ entries|length }} &lt;br&gt;

            test total: {{ testEntries|length }} &lt;br&gt;

          &lt;/div&gt;&lt;!-- /.testing --&gt;


                {% if entries|length %}
                    {% set activeClass = &quot; active&quot; %}
                    {% for entry in entries %}
                        {% set relatedIds = relatedIds ~ entry.id %}
                        {% if not loop.last %}
                            {% set relatedIds = relatedIds ~ &quot;,&quot; %}
                        {% endif %}

              more code here
                        
                    {% endfor %}                    
                {% endif %}
                
        more code here
        
        {% endfor %}
</code></pre>
<p>In the above loop I expect the entries to have results but I get zero results in my test div.</p>
<blockquote>
<p>survivor: Judy Abrams</p>
<p>theme: 12309</p>
<p>ids:</p>
<p>total results: 0</p>
<p>test total: 0</p>
</blockquote>
<p>Have confirmed that there should be 3 entries that match the <strong>entries</strong> or <strong>testEntries</strong> variable by looking at specific entries in the control panel.</p>

CC BY-SA 4.0
2020-01-27T16:49:57.507Z
Does this work? `{% set entries = craft.entries.section('survivorAssets').relatedTo(['and',{ targetElement: theme },{ targetElement: survivor }]).orderBy('assetOrder').all() %}`
Oli
CC BY-SA 4.0
2020-01-27T17:14:15.800Z
@Oli Thank you. Can't believe I made a rookie mistake like that. Thanks for your time.
CreateSean
CC BY-SA 4.0
2020-01-27T19:08:11.930Z
Can one of you add it as an official answer? ;)
Brad Bell
<templating><relations><relatedto>
Multiple Relations Trouble
# Multiple Relations Trouble

(Asked by: username_0 on 2020-01-27)

I'm having trouble setting entries with multiple relations.
during testing I've hard coded the theme to 1 specific category
{% set themeID = "12309" %}
{% set theme = craft.categories.group('survivorThemes').id(themeID).all() %}

I then set this
{% set survivors = craft.entries.section('authors').includeInRecollection('1').relatedTo({ sourceElement: relatedAssetIds }).orderBy('lastName asc').limit(null).all() %}  
and then a for loop
        {% for survivor in survivors %}
            {% set relatedIds = "" %}






{# this should work but doesn't #}
            {% set entries = 
                craft.entries.section('survivorAssets')
                .relatedTo('and', { targetElement: themeID },{ targetElement: survivor })
                .orderBy('assetOrder')
                .all() 
            %}  

{# this should also work but doesn't #}
            {% set testEntries = craft.entries.section('survivorAssets')
                .relatedTo('and', {targetElement: survivor, field: 'relatedSurvivor'}, {targetElement: themeID, field: 'themes'})
                .orderBy('assetOrder')
                .all()  %}






          

            survivor: {{ survivor.title }} 

            theme: {{ themeID }} 

            ids: {{ relatedIds}} 

            total results: {{ entries|length }} 

            test total: {{ testEntries|length }} 

          


                {% if entries|length %}
                    {% set activeClass = " active" %}
                    {% for entry in entries %}
                        {% set relatedIds = relatedIds ~ entry.id %}
                        {% if not loop.last %}
                            {% set relatedIds = relatedIds ~ "," %}
                        {% endif %}

              more code here
                        
                    {% endfor %}                    
                {% endif %}
                
        more code here
        
        {% endfor %}

In the above loop I expect the entries to have results but I get zero results in my test div.

survivor: Judy Abrams
theme: 12309
ids:
total results: 0
test total: 0

Have confirmed that there should be 3 entries that match the entries or testEntries variable by looking at specific entries in the control panel.

**Tags:** templating, relations, relatedto

> **Comments:**
> **username_1**: Does this work? `{% set entries = craft.entries.section('survivorAssets').relatedTo(['and',{ targetElement: theme },{ targetElement: survivor }]).orderBy('assetOrder').all() %}`  
> **username_0**: @username_1 Thank you. Can't believe I made a rookie mistake like that. Thanks for your time.  
> **username_2**: Can one of you add it as an official answer? ;)  

---

## 1 answers

### Answer by username_1 on 2020-01-28. Score: 1 | Accepted answer

The relatedTo parameter can take an object, an element ID or an array of element objects and/or IDs. In your case the latter is expected so wrapping your arguments in an array should fix the issue:
{% set entries = craft
                .entries
                .section('survivorAssets')
                .relatedTo(['and',{ targetElement: theme },{ targetElement: survivor }])
                .orderBy('assetOrder')
                .all() %}


---

