1

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? :(

1
  • You're missing a closing square bracket fyi...
    – Jalen Davenport
    Commented Apr 4, 2018 at 17:45

1 Answer 1

1

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()
%}
2
  • 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
    Commented Jun 22, 2020 at 7:57
  • @Brimby it's in the documentation I linked in my post Commented Jun 23, 2020 at 13:01

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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