Prevent queries based on condition I have a set of parameters that need to be checked before outputting an entry in a particular section of a website. The code for that looks somewhat like this:

{% for slide in craft.entries.section('events').featured('1').order('dateTime asc').limit(2) if (slide.dateTime|date_modify("tomorrow 5am")|date("c")) &gt;= now|date("c") %}


The problem is that it obviously is looping through all entries, even those that do not match my conditional based on the date. Is there a way to prevent the loop through entries that don't match that condition to prevent bloat as there will eventually be thousands of entries that it would be looped through that do not end up being output due to the conditional.
I don't think you're going to be able to do what you're looking for purely through Twig.

You can, however, write a plugin that either uses a service and variable or a Template Hook, so you can drop down to the PHP level and use DbCommand's where to apply your extra date conditionals to your SQL query directly.