Answers.Body: <p>I need someone more experienced with Craft to vet this, but it seems that this is working:</p>
  
  <p>Supplying an array to relatedTo returns results if it matches one <strong>OR</strong> the other entry.</p>
  
  <pre><code>$projectCriterea = craft()-&gt;elements-&gt;getCriteria(ElementType::Entry);
  $projectCriterea-&gt;section = 'projects';
  $projectCriterea-&gt;relatedTo = [$themeEntry, $yearCat];
  $projectResults = $projectCriterea-&gt;find();
  </code></pre>
  
  <p>If you supply "and" as the first entry in the array, it only returns results that are related to <strong>BOTH</strong> entries.</p>
  
  <pre><code>$projectCriterea = craft()-&gt;elements-&gt;getCriteria(ElementType::Entry);
  $projectCriterea-&gt;section = 'projects';
  $projectCriterea-&gt;relatedTo = ["and", $themeEntry, $yearCat];
  $projectResults = $projectCriterea-&gt;find();
  </code></pre>
  
  <p>This was figured out by tinkering and guessing, hence I'm not sure it's the "correct" way to do this. It also doesn't let me search individual custom entries type fields, but this does do what I was after.</p>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2016-09-27T22:05:56.907Z
Answers.Text: Hey @JamesNZ – your code looks legit. For some more `relatedTo` examples – including how to search for relations made in specific fields – check out [my answer](http://craftcms.stackexchange.com/a/16475/1098) to a similar question.
Answers.UserDisplayName: Mats Mikkel Rummelhoff
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2016-09-27T23:04:31.730Z
Answers.Text: Hey @mats-mikkel-rummelhoff - Perfect! That shows me exactly what I wanted to do next. Thanks :)
Answers.UserDisplayName: JamesNZ
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2016-09-27T21:09:24.500Z
Answers.LastActivityDate: 2016-09-27T21:09:24.500Z
Answers.UserDisplayName: JamesNZ
Body: <p>I have a channel (projects) that has two different <strong>entries fields</strong> (year &amp; research theme), both of which I want to be able to search in a plugin.</p>
  
  <p><a href="https://craftcms.com/docs/relations#the-relatedTo-param" rel="nofollow">The docs for the relatedTo</a> entries method show under the heading "Passing Multiple Relation Criteria" that it's possible to do this within twig, however I'm not sure how to do this in my plugin using php. Obviously the below won't work:</p>
  
  <pre><code># Find all projects that match the supplied year and research theme.
  $projectCriterea = craft()-&gt;elements-&gt;getCriteria(ElementType::Entry);
  $projectCriterea-&gt;section = 'projects';
  
  # Something like this?
  $projectCriterea-&gt;customField1-&gt;relatedTo = $yearEntryModel;
  $projectCriterea-&gt;customField2-&gt;relatedTo = $researchThemeEntryModel;
  
  $projects = $projectCriterea-&gt;find();
  </code></pre>
  
  <p>Any help would be amazing. Thanks.</p>
  
Tags: <entries><relations><entries-field><relatedto>
Title: Passing Multiple Relation Criteria In Plugin
ThreadText: # Passing Multiple Relation Criteria In Plugin
  
  (Asked by: username_0 on 2016-09-27)
  
  I have a channel (projects) that has two different **entries fields** (year & research theme), both of which I want to be able to search in a plugin.
  
  [The docs for the relatedTo](https://craftcms.com/docs/relations#the-relatedTo-param) entries method show under the heading "Passing Multiple Relation Criteria" that it's possible to do this within twig, however I'm not sure how to do this in my plugin using php. Obviously the below won't work:
  
  ```
  # Find all projects that match the supplied year and research theme.
  $projectCriterea = craft()->elements->getCriteria(ElementType::Entry);
  $projectCriterea->section = 'projects';
  
  # Something like this?
  $projectCriterea->customField1->relatedTo = $yearEntryModel;
  $projectCriterea->customField2->relatedTo = $researchThemeEntryModel;
  
  $projects = $projectCriterea->find();
  
  ```
  
  Any help would be amazing. Thanks.
  
  **Tags:** entries, relations, entries-field, relatedto
  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_0 on 2016-09-27. Score: 2 | Accepted answer
  
  I need someone more experienced with Craft to vet this, but it seems that this is working:
  
  Supplying an array to relatedTo returns results if it matches one **OR** the other entry.
  
  ```
  $projectCriterea = craft()->elements->getCriteria(ElementType::Entry);
  $projectCriterea->section = 'projects';
  $projectCriterea->relatedTo = [$themeEntry, $yearCat];
  $projectResults = $projectCriterea->find();
  
  ```
  
  If you supply "and" as the first entry in the array, it only returns results that are related to **BOTH** entries.
  
  ```
  $projectCriterea = craft()->elements->getCriteria(ElementType::Entry);
  $projectCriterea->section = 'projects';
  $projectCriterea->relatedTo = ["and", $themeEntry, $yearCat];
  $projectResults = $projectCriterea->find();
  
  ```
  
  This was figured out by tinkering and guessing, hence I'm not sure it's the "correct" way to do this. It also doesn't let me search individual custom entries type fields, but this does do what I was after.
  
  > **Comments:**
  > **username_1**: Hey @username_0 – your code looks legit. For some more `relatedTo` examples – including how to search for relations made in specific fields – check out [my answer](http://craftcms.stackexchange.com/a/16475/1098) to a similar question.  
  > **username_0**: Hey @username_1-mikkel-username_1 - Perfect! That shows me exactly what I wanted to do next. Thanks :)  
  
  ---
  
  