1

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?

5
  • 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. May 10, 2017 at 19:17
  • I would say create a variable in a plugin to handle this, have it return the find() call. May 10, 2017 at 19:19
  • 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
    May 10, 2017 at 19:28
  • @LindseyD, you should post your Slack solution in here. I'm sure this will help some people. May 10, 2017 at 21:05
  • @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
    May 10, 2017 at 21:07

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.