2

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.

carlcs
  • 36,220
  • 5
  • 62
  • 139
Alex Rubin
  • 85
  • 2
  • 6

2 Answers2

4

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 }
    ]
}) %}
carlcs
  • 36,220
  • 5
  • 62
  • 139
1

Not the way you do it, but Brandon's answer to this question is the best workaround.

Paul
  • 6,338
  • 12
  • 26
  • 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 Nov 24 '14 at 15:49