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.

3

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 }
    ]
}) %}
| improve this answer | |
  • Thanks Carics. This approach definitely works and, in my opinion, is a much cleaner one. – Alex Rubin Nov 25 '14 at 13:30
  • 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)! – carlcs Nov 25 '14 at 14:27
1

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

| improve this answer | |
  • 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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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