<p>You can simply get all the relevant categories at once and combine your <code>relatedTo</code> parameters with a single <code>and</code> operator:</p>

<pre><code>{% set issue = craft.entries({ section: 'issues', slug: 'october-2014' }).first() %}
{% set categories = craft.categories({ group: 'articles', slug: 'category-slug-one, category-slug-two, category-slug-three' }) %}

{% set entries = craft.entries({
    section: 'articles',
    relatedTo: [
        'and',
        { targetElement: issue },
        { targetElement: categories }
    ]
}) %}
</code></pre>

CC BY-SA 3.0
2014-11-25T13:30:08.773Z
Thanks Carics. This approach definitely works and, in my opinion, is a much cleaner one.
Alex Rubin
CC BY-SA 3.0
2014-11-25T14:27:33.480Z
Yes, in your case it's possible to get by without the workaround using IDs. But this is not always the case (see [another example here](http://craftcms.stackexchange.com/q/1948/125))!
carlcs
CC BY-SA 3.0
2014-11-24T16:00:20.767Z
2014-11-25T09:41:59.377Z
2014-11-25T09:41:59.377Z
carlcs
<p>Not the way you do it, but Brandon's answer to <a href="https://craftcms.stackexchange.com/questions/4560/how-can-i-create-an-elementcriteriamodel-with-and-and-or">this question</a> is the best workaround.</p>

CC BY-SA 3.0
2014-11-24T15:49:19.810Z
Thanks Paul. Yeah, I knew that what I posted wasn't possible, but it was a good way of articulating the attempted end result.
Alex Rubin
CC BY-SA 3.0
2014-11-24T15:41:43.777Z
2014-11-24T15:41:43.777Z
2017-04-13T12:51:00.200Z
Paul
<p>Is the following possible:</p>

<pre><code>{% set issue = craft.entries(section: 'issues', slug: 'october-2014').first() %}

{% set categoryOne = craft.categories({ group: 'articles', slug: 'category-slug-one'}) %}
{% set categoryTwo = craft.categories({ group: 'articles', slug: 'category-slug-two'}) %}
{% set categoryThree = craft.categories({ group: 'articles', slug: 'category-slug-three'}) %}

{% for entry in craft.entries({
    section: 'articles',
    relatedTo: ['and',
        ['or',
            { targetElement: categoryOne },
            { targetElement: categoryTwo },
            { targetElement: categoryThree }
        ],
        { targetElement: issue }
    ]
}) %}

    {{ entry.title }}

{% endfor %}
</code></pre>

<p>Attempting to return articles associated with a specific issue from within one of three specific categories.</p>

<p>It appears the parseRelationParam function looks at the first array element to determine the operator but I'm hoping someone has a solution. </p>

<templating><entries><categories><relations>
relatedTo 'and' with 'or'
# relatedTo 'and' with 'or'

(Asked by: username_0 on 2014-11-24)

Is the following possible:
{% set issue = craft.entries(section: 'issues', slug: 'october-2014').first() %}

{% set categoryOne = craft.categories({ group: 'articles', slug: 'category-slug-one'}) %}
{% set categoryTwo = craft.categories({ group: 'articles', slug: 'category-slug-two'}) %}
{% set categoryThree = craft.categories({ group: 'articles', slug: 'category-slug-three'}) %}

{% for entry in craft.entries({
    section: 'articles',
    relatedTo: ['and',
        ['or',
            { targetElement: categoryOne },
            { targetElement: categoryTwo },
            { targetElement: categoryThree }
        ],
        { targetElement: issue }
    ]
}) %}

    {{ entry.title }}

{% endfor %}

Attempting to return articles associated with a specific issue from within one of three specific categories.
It appears the parseRelationParam function looks at the first array element to determine the operator but I'm hoping someone has a solution.

**Tags:** templating, entries, categories, relations

---

## 2 answers

### Answer by username_1 on 2014-11-24. Score: 4 | Accepted answer

You can simply get all the relevant categories at once and combine your relatedTo parameters with a single and operator:
{% set issue = craft.entries({ section: 'issues', slug: 'october-2014' }).first() %}
{% set categories = craft.categories({ group: 'articles', slug: 'category-slug-one, category-slug-two, category-slug-three' }) %}

{% set entries = craft.entries({
    section: 'articles',
    relatedTo: [
        'and',
        { targetElement: issue },
        { targetElement: categories }
    ]
}) %}

> **Comments:**
> **username_0**: Thanks Carics. This approach definitely works and, in my opinion, is a much cleaner one.  
> **username_1**: Yes, in your case it's possible to get by without the workaround using IDs. But this is not always the case (see [another example here](http://craftcms.stackexchange.com/q/1948/125))!  

---

### Answer by username_2 on 2014-11-24. Score: 1

Not the way you do it, but Brandon's answer to [this question](https://craftcms.stackexchange.com/questions/4560/how-can-i-create-an-elementcriteriamodel-with-and-and-or) is the best workaround.

> **Comments:**
> **username_0**: Thanks Paul. Yeah, I knew that what I posted wasn't possible, but it was a good way of articulating the attempted end result.  

---

