<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>

CC BY-SA 3.0
2015-06-30T04:00:03.667Z
2015-06-30T04:00:03.667Z
2017-04-13T12:51:00.253Z
Brad Bell
<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>

CC BY-SA 3.0
2015-06-29T18:19:44.387Z
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?
Brad Bell
CC BY-SA 3.0
2015-06-29T23:02:20.380Z
yes that's correct
evolution7_thoai
<search><elementcriteriamodel><elementtype>
Complex search (and/or)
# 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'=> [],// 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.


---

