Im trying to do an OR filter for craft.entries and not sure of the syntax

so like this

{% set startedThisYear = craft.entries.find({ section: 'exhibitions', startDate: ">= " ~startDate, startDate: "<= " ~endDate, order:'startDate desc'}) %}

if i wanted it to be

startDate: ">= " ~startDate or startDate: "<= " ~endDate


  • Keith, see my question here for a similar problem that I solved using a workaround collecting entry IDs.
    – carlcs
    Jan 28 '15 at 22:46
  • The 'duplicate' is actually a much more complicated scenario that might actually confuse people — I'm not sure if it's such a good match. But not a big deal. Problem solved. Jan 29 '15 at 20:18
  • Yea I agree, I dont think the answer they gave in the "match" is the right answer here. What I was looking for was the syntax to do 'and' and 'or' conditionals in the craft.entries. queries, where as the other questions solution was to do multiple queries and combine them together. Jan 29 '15 at 22:40

I think that you actually want to use 'and' rather than 'or'. 'Or' would return all entries. This is also assuming that you have predefined the 'startDate' and 'endDate' variables.

{% set params = {
    section: 'exhibitions',
    startDate: 'and, >= ' ~ startDate ~ ', <= ' ~ endDate,
    order:'startDate desc'
} %}

{% set startedThisYear = craft.entries(params) %}

If you haven't already done so, you may need to format 'startDate' and 'endDate' variables first.

startDate: 'and, >= ' ~ startDate|date('Y-m-d') ~ ', <= ' ~ endDate|date('Y-m-d')

See this answer for another example.


Not the answer you're looking for? Browse other questions tagged or ask your own question.