<p>My section has two numeric fields, <code>lorem</code> and <code>ipsum</code>. It's possible for users to enter any integer they want into these two fields.</p>

<p><strong>I want to grab all results where <code>lorem</code> is greater than <code>ipsum</code>.</strong></p>

<p>Here's my starting point...</p>

<pre><code>{% set results = craft.entries.section('foo').limit(3) %}
</code></pre>

<p>How would I alter the above Element Criteria Model to only retrieve entries where the value of <code>lorem</code> is greater than the value of <code>ipsum</code>?</p>

CC BY-SA 3.0
2017-05-10T19:17:41.063Z
Pretty sure you're going to have to get your hands dirty to achieve this. Maybe do a raw query to return all of the record IDs which meet your lorem / ipsum criterion, and then use those IDs in the main ElementCriteriaModel query, so you still get Craft to do the heavy lifting.
Stephen Lewis
CC BY-SA 3.0
2017-05-10T19:19:08.207Z
I would say create a variable in a plugin to handle this, have it return the find() call.
Rick Kukiela
CC BY-SA 3.0
2017-05-10T19:28:14.270Z
Crazy... I think you guys are right, I'll need to dig into a plugin to make this work. I'm a bit surprised there isn't a simpler solution. Thanks Stephen & SublymeRick!
Lindsey D
CC BY-SA 3.0
2017-05-10T21:05:52.843Z
@LindseyD, you should post your Slack solution in here. I'm sure this will help some people.
Max Strebel
CC BY-SA 3.0
2017-05-10T21:07:38.967Z
@LazyPirate I haven't actually tried it yet, so I'm not sure if/how it works. But I'll try to post back when I do!
Lindsey D
<templating><elementcriteriamodel><comparisons>
When constructing an ECM, is it possible to compare two values?
# When constructing an ECM, is it possible to compare two values?

(Asked by: username_0 on 2017-05-10)

My section has two numeric fields, lorem and ipsum. It's possible for users to enter any integer they want into these two fields.
I want to grab all results where lorem is greater than ipsum.
Here's my starting point...
{% set results = craft.entries.section('foo').limit(3) %}

How would I alter the above Element Criteria Model to only retrieve entries where the value of lorem is greater than the value of ipsum?

**Tags:** templating, elementcriteriamodel, comparisons
> **Comments:**
> **username_1**: Pretty sure you're going to have to get your hands dirty to achieve this. Maybe do a raw query to return all of the record IDs which meet your lorem / ipsum criterion, and then use those IDs in the main ElementCriteriaModel query, so you still get Craft to do the heavy lifting.  
> **username_2**: I would say create a variable in a plugin to handle this, have it return the find() call.  
> **username_0**: Crazy... I think you guys are right, I'll need to dig into a plugin to make this work. I'm a bit surprised there isn't a simpler solution. Thanks Stephen & SublymeRick!  
> **username_3**: @LindseyD, you should post your Slack solution in here. I'm sure this will help some people.  
> **username_0**: @LazyPirate I haven't actually tried it yet, so I'm not sure if/how it works. But I'll try to post back when I do!  

---

## 0 answers

