<p>Aren't you missing the <code>-&gt;find()</code> on the last bit?</p>

<pre><code>$entries = craft()-&gt;elements-&gt;getCriteria(ElementType::Entry, [
    'section'           =&gt; 'products',
    'relatedTo'         =&gt; ['and', $fabric_categories, $color_categories],
])-&gt;find();
return $entries;
</code></pre>

CC BY-SA 4.0
2019-02-03T12:29:16.890Z
2019-02-03T12:29:16.890Z
Oli
<p>I am trying to return entries that relate to a series of categories.</p>

<p>For example, I am trying to return clothing, in this example, I want to <strong>return all entries related to (flannel or denim) and (blue or red)</strong> in the products channel.</p>

<p>Flannel, denim, blue and red are all apart of the same category group called: filters, and the category field handle is productFilters</p>

<p>I was trying to return all those entries but it returns 0 entries, any help is appreciated. I know I can do this probably using the craft cms element query in the template but I need to do this in a plugin.</p>

<pre><code>$color_categories = craft()-&gt;elements-&gt;getCriteria(ElementType::Category, [
    'slug'  =&gt; ['blue', 'red'],
    'group' =&gt; 'filters'
])-&gt;find();

$fabric_categories = craft()-&gt;elements-&gt;getCriteria(ElementType::Category, [
    'slug'  =&gt; ['denim', 'flannel'],
    'group' =&gt; 'filters'
])-&gt;find();

$entries = craft()-&gt;elements-&gt;getCriteria(ElementType::Entry, [
    'section'           =&gt; 'products',
    'relatedTo'         =&gt; ['and', $fabric_categories, $color_categories],
]);

return $entries;
</code></pre>

CC BY-SA 4.0
2019-02-03T16:15:54.283Z
Just to help narrow down the potential issues— `$color_categories` and `$fabric_categories` both contain the expected results? And, in your Category group, are any of the expected results nested under one another?
August Miller
CC BY-SA 4.0
2019-02-06T00:40:01.293Z
I figured out the issue, I needed to search all entries related to the fabric categories, and other the entries related to the color categories, getting the id's all those two sets of results, do an array intersect on them, returning all the id's of entries that had (denim or flannel) and (blue or red)
Brad
<plugin-development><categories><elementcriteriamodel><relatedto><craft2>
Multiple and or relatedTo in plugin element criteria
# Multiple and or relatedTo in plugin element criteria

(Asked by: username_0 on 2019-01-31)

I am trying to return entries that relate to a series of categories.
For example, I am trying to return clothing, in this example, I want to return all entries related to (flannel or denim) and (blue or red) in the products channel.
Flannel, denim, blue and red are all apart of the same category group called: filters, and the category field handle is productFilters
I was trying to return all those entries but it returns 0 entries, any help is appreciated. I know I can do this probably using the craft cms element query in the template but I need to do this in a plugin.
$color_categories = craft()->elements->getCriteria(ElementType::Category, [
    'slug'  => ['blue', 'red'],
    'group' => 'filters'
])->find();

$fabric_categories = craft()->elements->getCriteria(ElementType::Category, [
    'slug'  => ['denim', 'flannel'],
    'group' => 'filters'
])->find();

$entries = craft()->elements->getCriteria(ElementType::Entry, [
    'section'           => 'products',
    'relatedTo'         => ['and', $fabric_categories, $color_categories],
]);

return $entries;

**Tags:** plugin-development, categories, elementcriteriamodel, relatedto, craft2

> **Comments:**
> **username_1**: Just to help narrow down the potential issues— `$color_categories` and `$fabric_categories` both contain the expected results? And, in your Category group, are any of the expected results nested under one another?  
> **username_0**: I figured out the issue, I needed to search all entries related to the fabric categories, and other the entries related to the color categories, getting the id's all those two sets of results, do an array intersect on them, returning all the id's of entries that had (denim or flannel) and (blue or red)  

---

## 1 answers

### Answer by username_2 on 2019-02-03. Score: 2 | Accepted answer

Aren't you missing the ->find() on the last bit?
$entries = craft()->elements->getCriteria(ElementType::Entry, [
    'section'           => 'products',
    'relatedTo'         => ['and', $fabric_categories, $color_categories],
])->find();
return $entries;


---

