<p>When you are going to apply an <code>and</code> in your <code>relatedTo</code> in Craft 3 it expects the following arguments to be arrays with the structure like <a href="https://docs.craftcms.com/v2/relations.html#passing-multiple-relation-criteria" rel="nofollow noreferrer">here</a> </p>

<pre><code>{% set entries = craft
    .entries
    .section('institutions')
    .relatedTo(['and', 
        {element: state}, // &lt;- or targetElement / sourceElement
        {element: solution}
    ])
    .limit(4) 
    .all()
%}
</code></pre>

CC BY-SA 4.0
2020-06-22T07:57:30.700Z
You saved me with the `{element: variable}` syntax. Where did you learn that from? I can't find syntax like that anywhere in the docs.
Brimby
CC BY-SA 4.0
2020-06-23T13:01:02.307Z
@Brimby it's in the documentation I linked in my post
Robin Schambach
CC BY-SA 3.0
2018-04-04T20:51:08.323Z
2018-04-04T20:51:08.323Z
Robin Schambach
<p>Here we go:</p>

<pre><code>{% set state = craft.categories.group('locations').level(1).title(entry.title).one() %}
{% set solution = craft.categories.group('institutionSolutions').title(entry.parent.title).one() %}
{% set entries = craft.entries.section('institutions').relatedTo('and', state, solution).limit(4) %}

   {% for entry in entries %}
       {{ entry.title }}
   {% endfor %}
</code></pre>

<p>The following code does work as expected in Craft 2. According to the docs in Craft 3 we have to use the array brackets. So this</p>

<pre><code>{% set entries = craft.entries.section('institutions').relatedTo('and', state, solution).limit(4) %}
</code></pre>

<p>will become to this</p>

<pre><code>{% set entries = craft.entries.section('institutions').relatedTo(['and', state, solution).limit(4) %}
</code></pre>

<p>as a result I see the following message:</p>

<p>array_merge(): Argument #2 is not an array</p>

<p>What am I doing wrong? :(</p>

CC BY-SA 3.0
2018-04-04T17:45:50.673Z
You're missing a closing square bracket fyi...
Jalen Davenport
<craft3><array>
Argument #2 is not an array
# Argument #2 is not an array

(Asked by: username_0 on 2018-04-04)

Here we go:
{% set state = craft.categories.group('locations').level(1).title(entry.title).one() %}
{% set solution = craft.categories.group('institutionSolutions').title(entry.parent.title).one() %}
{% set entries = craft.entries.section('institutions').relatedTo('and', state, solution).limit(4) %}

   {% for entry in entries %}
       {{ entry.title }}
   {% endfor %}

The following code does work as expected in Craft 2. According to the docs in Craft 3 we have to use the array brackets. So this
{% set entries = craft.entries.section('institutions').relatedTo('and', state, solution).limit(4) %}

will become to this
{% set entries = craft.entries.section('institutions').relatedTo(['and', state, solution).limit(4) %}

as a result I see the following message:
array_merge(): Argument #2 is not an array
What am I doing wrong? :(

**Tags:** craft3, array
> **Comments:**
> **username_1**: You're missing a closing square bracket fyi...  

---

## 1 answers

### Answer by username_2 on 2018-04-04. Score: 1 | Accepted answer

When you are going to apply an and in your relatedTo in Craft 3 it expects the following arguments to be arrays with the structure like here 
{% set entries = craft
    .entries
    .section('institutions')
    .relatedTo(['and', 
        {element: state}, // <- or targetElement / sourceElement
        {element: solution}
    ])
    .limit(4) 
    .all()
%}

> **Comments:**
> **username_3**: You saved me with the `{element: variable}` syntax. Where did you learn that from? I can't find syntax like that anywhere in the docs.  
> **username_2**: @Brimby it's in the documentation I linked in my post  

---

