<p>I'm not sure you can achieve this in one query.</p>
<p>The easiest solution I can think of to your problem requires 3 queries:</p>
<pre><code>{% set peopleIds = craft.entries().section('people').type('Employees').ids() %}
{% set insightIds = craft.entries().section('insights').ids() %}
{% set query = craft.entries().id(peopleIds|merge(insightIds))
</code></pre>
<p>The first 2 queries are executed and return the ids of the matching entries. You can then create  your EntryQuery using the ids as the only criterion.</p>

CC BY-SA 4.0
2020-09-15T19:15:19.430Z
2020-09-15T19:15:19.430Z
nstCactus
<p>Thank you @nstCactus, that's a great idea! Just for anyone looking for the PHP equivalent:</p>
<pre><code>$peopleIds = \craft\elements\Entry::find()-&gt;section('people')-&gt;type('Employees')-&gt;ids();
$insightIds = \craft\elements\Entry::find()-&gt;section('insights')-&gt;ids();
$query-&gt;id(array_merge($peopleIds, $insightsIds));
</code></pre>

CC BY-SA 4.0
2020-09-15T20:55:19.710Z
2020-09-15T20:55:19.710Z
Adam Tsai
<p>I think the best way to pose this question is by giving an example:</p>
<p>Given a variable $query of type craft\elements\db\EntryQuery, I'd like to get entries from 2 different sections: &quot;people&quot; and &quot;news&quot;. Of the entries from the &quot;people&quot; section, I only want ones with entry type &quot;Employees&quot;. How would I set this up so that the &quot;type&quot; filter only applies to 1 section? If I were querying them individually, they would look like this:</p>
<pre><code>$query-&gt;section('people')-&gt;type('Employees');
$query-&gt;section('insights');
</code></pre>
<p>How can I do this in 1 query? Thanks!</p>

CC BY-SA 4.0
2020-09-15T18:38:28.397Z
Alternatively, could I create 2 queries and combine them somehow? I need to preserve it as a query, so I can't just use .all() and merge the arrays.
Adam Tsai
<craft3><api>
How to query EntryQuery for multiple sections with varying types
# How to query EntryQuery for multiple sections with varying types

(Asked by: username_0 on 2020-09-15)

I think the best way to pose this question is by giving an example:
Given a variable $query of type craft\elements\db\EntryQuery, I'd like to get entries from 2 different sections: "people" and "news". Of the entries from the "people" section, I only want ones with entry type "Employees". How would I set this up so that the "type" filter only applies to 1 section? If I were querying them individually, they would look like this:
$query->section('people')->type('Employees');
$query->section('insights');

How can I do this in 1 query? Thanks!

**Tags:** craft3, api
> **Comments:**
> **username_0**: Alternatively, could I create 2 queries and combine them somehow? I need to preserve it as a query, so I can't just use .all() and merge the arrays.  

---

## 2 answers

### Answer by username_1 on 2020-09-15. Score: 3 | Accepted answer

I'm not sure you can achieve this in one query.
The easiest solution I can think of to your problem requires 3 queries:
{% set peopleIds = craft.entries().section('people').type('Employees').ids() %}
{% set insightIds = craft.entries().section('insights').ids() %}
{% set query = craft.entries().id(peopleIds|merge(insightIds))

The first 2 queries are executed and return the ids of the matching entries. You can then create  your EntryQuery using the ids as the only criterion.


---

### Answer by username_0 on 2020-09-15. Score: 2

Thank you @nstCactus, that's a great idea! Just for anyone looking for the PHP equivalent:
$peopleIds = \craft\elements\Entry::find()->section('people')->type('Employees')->ids();
$insightIds = \craft\elements\Entry::find()->section('insights')->ids();
$query->id(array_merge($peopleIds, $insightsIds));


---

