Answers.Body: <p>I don't think it's possible to do what you're trying to do in a single ElementCriteriaModel query.</p>
  
  <p><a href="https://craftcms.stackexchange.com/questions/4560/how-can-i-create-an-elementcriteriamodel-with-and-and-or">These</a> <a href="https://craftcms.stackexchange.com/q/587/57">questions</a> are basically asking the same thing and can confirm it.</p>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-06-30T04:00:03.667Z
Answers.LastActivityDate: 2015-06-30T04:00:03.667Z
Answers.LastEditDate: 2017-04-13T12:51:00.253Z
Answers.UserDisplayName: Brad Bell
Body: <p>I want to search for Entries of the same channel/section based on their type. Let's say, we are a travel company with two types of tours: "guided group" and "private". For group tours, we want trips associated with a particular provider. For private tours, we want trips less than a certain price (this field is N/A for group journeys).</p>
  
  <p>In the controller:</p>
  
  <pre><code>$criteriaFilters = [
      'section'=&gt;'journeys',
      'relatedTo'=&gt; [&lt;ids of the provider&gt;],// Should be for group only
      'price'=&gt;'&lt;10', // Should be for private tour only
  ];
  $criteria = craft()-&gt;elements-&gt;getCriteria(
      ElementType::Entry,
      $criteriaFilters
  );
  </code></pre>
  
  <p>I need to retrieve them all in an ElementCriteriaModel object, via one SQL query. I don't want to get all private and guided tours separately and then combine them because that doesn't work well with pagination.</p>
  
  <p>What do you think is best to achieve this? (in PHP, not Twig)</p>
  
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2015-06-29T18:19:44.387Z
Comments.Text: Just to be clear, you want to be able to search where `relatedTo` is equal to some list of entries OR `price` is less than some amount and get a single result set back?
Comments.UserDisplayName: Brad Bell
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2015-06-29T23:02:20.380Z
Comments.Text: yes that's correct
Comments.UserDisplayName: evolution7_thoai
Tags: <search><elementcriteriamodel><elementtype>
Title: Complex search (and/or)
ThreadText: # Complex search (and/or)
  
  (Asked by: username_0 on 2015-06-26)
  
  I want to search for Entries of the same channel/section based on their type. Let's say, we are a travel company with two types of tours: "guided group" and "private". For group tours, we want trips associated with a particular provider. For private tours, we want trips less than a certain price (this field is N/A for group journeys).
  
  In the controller:
  
  ```
  $criteriaFilters = [
      'section'=>'journeys',
      'relatedTo'=> [<ids of the provider>],// Should be for group only
      'price'=>'<10', // Should be for private tour only
  ];
  $criteria = craft()->elements->getCriteria(
      ElementType::Entry,
      $criteriaFilters
  );
  
  ```
  
  I need to retrieve them all in an ElementCriteriaModel object, via one SQL query. I don't want to get all private and guided tours separately and then combine them because that doesn't work well with pagination.
  
  What do you think is best to achieve this? (in PHP, not Twig)
  
  **Tags:** search, elementcriteriamodel, elementtype
  
  > **Comments:**
  > **username_1**: Just to be clear, you want to be able to search where `relatedTo` is equal to some list of entries OR `price` is less than some amount and get a single result set back?  
  > **username_0**: yes that's correct  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_1 on 2015-06-30. Score: 1
  
  I don't think it's possible to do what you're trying to do in a single ElementCriteriaModel query.
  
  [These](https://craftcms.stackexchange.com/questions/4560/how-can-i-create-an-elementcriteriamodel-with-and-and-or) [questions](https://craftcms.stackexchange.com/q/587/57) are basically asking the same thing and can confirm it.
  
  
  ---
  
  