Answers.Body: <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>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2020-09-15T19:15:19.430Z
Answers.LastActivityDate: 2020-09-15T19:15:19.430Z
Answers.UserDisplayName: nstCactus
Answers.Body: <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>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2020-09-15T20:55:19.710Z
Answers.LastActivityDate: 2020-09-15T20:55:19.710Z
Answers.UserDisplayName: Adam Tsai
Body: <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>
  
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2020-09-15T18:38:28.397Z
Comments.Text: 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.
Comments.UserDisplayName: Adam Tsai
Tags: <craft3><api>
Title: How to query EntryQuery for multiple sections with varying types
ThreadText: # 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 @username_1, 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));
  
  ```
  
  
  ---
  
  