<p>The <code>relatedTo</code> parameter's <code>targetElement</code> property has to be an ElementCriteriaModel or a single category model:</p>

<pre><code>{% set featured = craft.categories.group('myCatGroup').slug('featured').first() %}
{% set caseStudies = craft.categories.group('myCatGroup').slug('case-studies') %}

{% set entries = craft.users({
    group: 'resource',
    relatedTo: [
        'and',
        { targetElement: featured },
        { targetElement: caseStudies }
    ]
}) %}
</code></pre>

CC BY-SA 3.0
2015-05-20T13:30:51.920Z
Why are we setting .first() for the featured category? This does work though just curious why the .first().
Bowenac
CC BY-SA 3.0
2015-05-20T14:24:19.567Z
It was just an example for a single category model instead of an ElementCriteriaModel.
carlcs
CC BY-SA 3.0
2015-05-20T06:11:01.223Z
2015-05-20T06:18:07.630Z
2015-05-20T06:18:07.630Z
carlcs
<p>I have searched and tried a few different ways but none have worked so not sure what is wrong.</p>

<p>Example say I have a few categories case studies, featured, articles, videos...</p>

<p>I have tried this way</p>

<pre><code>{% set category = craft.categories.group('resource').relatedTo(
    'and',
    { targetElement: featured },
    { targetElement: case studies }
) %}
{% set entries = craft.entries.relatedTo(category).limit(3).find() %}
</code></pre>

<p>I have tried this way</p>

<pre><code>{% set category = craft.categories({
    group: 'resource',
    relatedTo: [
        'and',
        { targetElement: featured },
        { targetElement: case-studies }
    ]
}) %}
{% set entries = craft.entries.relatedTo(category).limit(3).find() %}
</code></pre>

<p>I am wanting to find entries that use two categories together example case studies, and featured category.</p>

<templating><categories>
Get entries relatedTo multiple categories
# Get entries relatedTo multiple categories

(Asked by: username_0 on 2015-05-20)

I have searched and tried a few different ways but none have worked so not sure what is wrong.
Example say I have a few categories case studies, featured, articles, videos...
I have tried this way
{% set category = craft.categories.group('resource').relatedTo(
    'and',
    { targetElement: featured },
    { targetElement: case studies }
) %}
{% set entries = craft.entries.relatedTo(category).limit(3).find() %}

I have tried this way
{% set category = craft.categories({
    group: 'resource',
    relatedTo: [
        'and',
        { targetElement: featured },
        { targetElement: case-studies }
    ]
}) %}
{% set entries = craft.entries.relatedTo(category).limit(3).find() %}

I am wanting to find entries that use two categories together example case studies, and featured category.

**Tags:** templating, categories


---

## 1 answers

### Answer by username_1 on 2015-05-20. Score: 6 | Accepted answer

The relatedTo parameter's targetElement property has to be an ElementCriteriaModel or a single category model:
{% set featured = craft.categories.group('myCatGroup').slug('featured').first() %}
{% set caseStudies = craft.categories.group('myCatGroup').slug('case-studies') %}

{% set entries = craft.users({
    group: 'resource',
    relatedTo: [
        'and',
        { targetElement: featured },
        { targetElement: caseStudies }
    ]
}) %}

> **Comments:**
> **username_0**: Why are we setting .first() for the featured category? This does work though just curious why the .first().  
> **username_1**: It was just an example for a single category model instead of an ElementCriteriaModel.  

---

