<p>The only possible core solution to query for these entries in Twig is to query for entry IDs first, process them with <a href="http://twig.sensiolabs.org/doc/filters/merge.html" rel="nofollow"><code>merge</code></a> or <a href="http://buildwithcraft.com/docs/templating/filters#without" rel="nofollow"><code>without</code></a> and then pass the IDs to the <code>id</code> parameter of a new ElementCriteriaModel.</p>

<p>Other than your solution implementing a conditional in the for loop this works with <code>paginate</code> and <code>getNext</code> tags, you only query for the entry models you're after, but the cost of this is the extra queries you need to get the IDs.</p>

<pre><code>{% set futureEventsIds = craft.entries.eventStartDate('&gt;=' ~ (now.date)).ids() %}
{% set specialEventsIds = craft.entries.genericEventDate(':notempty:').ids() %}
{% set idParam = futureEventsIds|merge(specialEventsIds) %}

{% set allEvents = craft.entries.id(idParam).order('GREATEST(eventStartDate, genericEventDate) desc') %}
</code></pre>

CC BY-SA 3.0
2015-05-15T20:18:01.597Z
2015-05-15T20:18:01.597Z
carlcs
<p>Hmm, I can't think of how you would do this in Twig. But you may want to jump into PHP and perform your query a little more manually... <a href="https://craftcms.stackexchange.com/a/723/45">This answer</a> provides a few good ways to do that.</p>

<p>Specifically, I'd take a look into either a <a href="http://buildwithcraft.com/docs/plugins/variables" rel="nofollow noreferrer">custom variable</a> or a <a href="http://buildwithcraft.com/classreference/services/TemplatesService#hook-detail" rel="nofollow noreferrer">template hook</a>. I'm personally a huge fan of the <strong>template hook</strong>... it feels like unlimited power in a tiny package.</p>

<p>Once you're in PHP, you can use Craft's <code>buildElementsQuery</code> along with Yii's <code>DbCommand</code> to generate your own complex query. For a rough example, check out <a href="https://craftcms.stackexchange.com/q/2786/45">this question and answer...</a></p>

CC BY-SA 3.0
2015-05-15T15:27:50.293Z
I'm with you with this option but is it too much to ask to do this inline as just a part of the craft.entries query?
Adam McCombs
CC BY-SA 3.0
2015-05-15T17:24:42.383Z
Agreed, a Twig-based solution would be preferred. But I don't have one, so I figured I'd leave you with this alternate approach instead. :)
Lindsey D
CC BY-SA 3.0
2015-05-15T05:29:35.517Z
2015-05-15T05:29:35.517Z
2017-04-13T12:51:00.200Z
Lindsey D
<p>Many years later - a solution by pulling the queries separately, then merging the arrays and sorting them. Docs <a href="https://twig.symfony.com/doc/3.x/filters/sort.html" rel="nofollow noreferrer">here</a></p>
<pre><code>{% set events      = craft.entries().section('events').theMainCategory(entry.id).orderBy('startDate asc').all() %}
{% set eventsOther = craft.entries().section('events').otherCategories(entry.id).orderBy('startDate asc').all() %}
{% set events      = events|merge(eventsOther) %}
    
{% for event in events|sort((a,b) =&gt; a.startDate &lt;=&gt; b.startDate) %}
    {# Display event #}
{% endfor %}
</code></pre>

CC BY-SA 4.0
2023-11-22T19:00:00.680Z
2023-11-22T19:00:00.680Z
kr37
<p>I may be wrong here as only just started learning Craft and its template system but would this not work? </p>

<pre><code>{% if (

    craft.entries.eventStartDate|date('U') &gt;= now|date('U')
    or
    craft.entries.genericEventDate != ""
)
%}

&lt;p&gt;Show this text!!&lt;/p&gt;

{% endif %}
</code></pre>

CC BY-SA 3.0
2015-05-15T08:00:10.337Z
2015-05-15T14:37:21.943Z
2015-05-15T14:37:21.943Z
Mark Bowen
<p>I have an for entry loop in which I need to look for two different field conditions. Separately they are:</p>

<pre><code>craft.entries.eventStartDate('&gt;=' ~ (now.date))

craft.entries.genericEventDate(':notempty:’)
</code></pre>

<p>How can I ask craft to look to see if <strong>either</strong> of these parameters is true?</p>

<p><strong>Update</strong></p>

<p>A work around is to pull the query without these paramaters and then run an if statement like:</p>

<p><code>{% if entry.eventStartDate &gt;= now.date or entry.genericEventDate is not empty %}</code></p>

<p>This works but it's not really ideal since the query is pulling more entries than necessary.</p>

<entries><entries-field><params>
Multiple craft.entries field parameters
# Multiple craft.entries field parameters

(Asked by: username_0 on 2015-05-14)

I have an for entry loop in which I need to look for two different field conditions. Separately they are:
craft.entries.eventStartDate('>=' ~ (now.date))

craft.entries.genericEventDate(':notempty:’)

How can I ask craft to look to see if either of these parameters is true?
Update
A work around is to pull the query without these paramaters and then run an if statement like:
{% if entry.eventStartDate >= now.date or entry.genericEventDate is not empty %}
This works but it's not really ideal since the query is pulling more entries than necessary.

**Tags:** entries, entries-field, params

---

## 4 answers

### Answer by username_1 on 2015-05-15. Score: 3

The only possible core solution to query for these entries in Twig is to query for entry IDs first, process them with merge or without and then pass the IDs to the id parameter of a new ElementCriteriaModel.
Other than your solution implementing a conditional in the for loop this works with paginate and getNext tags, you only query for the entry models you're after, but the cost of this is the extra queries you need to get the IDs.
{% set futureEventsIds = craft.entries.eventStartDate('>=' ~ (now.date)).ids() %}
{% set specialEventsIds = craft.entries.genericEventDate(':notempty:').ids() %}
{% set idParam = futureEventsIds|merge(specialEventsIds) %}

{% set allEvents = craft.entries.id(idParam).order('GREATEST(eventStartDate, genericEventDate) desc') %}


---

### Answer by username_2 on 2015-05-15. Score: 2

Hmm, I can't think of how you would do this in Twig. But you may want to jump into PHP and perform your query a little more manually... [This answer](https://craftcms.stackexchange.com/a/723/45) provides a few good ways to do that.

Specifically, I'd take a look into either a [custom variable](http://buildwithcraft.com/docs/plugins/variables) or a [template hook](http://buildwithcraft.com/classreference/services/TemplatesService#hook-detail). I'm personally a huge fan of the **template hook**... it feels like unlimited power in a tiny package.

Once you're in PHP, you can use Craft's `buildElementsQuery` along with Yii's `DbCommand` to generate your own complex query. For a rough example, check out [this question and answer...](https://craftcms.stackexchange.com/q/2786/45)

> **Comments:**
> **username_0**: I'm with you with this option but is it too much to ask to do this inline as just a part of the craft.entries query?  
> **username_2**: Agreed, a Twig-based solution would be preferred. But I don't have one, so I figured I'd leave you with this alternate approach instead. :)  

---

### Answer by username_3 on 2023-11-22. Score: 1

Many years later - a solution by pulling the queries separately, then merging the arrays and sorting them. Docs here
{% set events      = craft.entries().section('events').theMainCategory(entry.id).orderBy('startDate asc').all() %}
{% set eventsOther = craft.entries().section('events').otherCategories(entry.id).orderBy('startDate asc').all() %}
{% set events      = events|merge(eventsOther) %}
    
{% for event in events|sort((a,b) => a.startDate <=> b.startDate) %}
    {# Display event #}
{% endfor %}


---

### Answer by username_4 on 2015-05-15. Score: 0

I may be wrong here as only just started learning Craft and its template system but would this not work? 
{% if (

    craft.entries.eventStartDate|date('U') >= now|date('U')
    or
    craft.entries.genericEventDate != ""
)
%}

Show this text!!

{% endif %}


---

