<p>This should work below. Rather than querying all entries and looping through, just select the entries you need (ie. <code>now</code>) and limit them. </p>

<pre><code>{% set upcomingEvents = craft.entries.section('events').eventDate('&gt;= '~now).limit(2) %}
{% for event in upcomingEvents %}
    &lt;!-- markup here --&gt;
{% endfor %} 
</code></pre>

CC BY-SA 3.0
2016-08-05T19:23:02.917Z
Hi, thanks. Just tried this but its giving me a "Fatal error: Call to a member function getTimestamp() on boolean" with a large call stack table.
dace
CC BY-SA 3.0
2016-08-05T19:26:16.070Z
Should also clarify that the date I need to make sure it's displaying after today is the eventDate of the entry (a custom field I set) and not the published or posted date.
dace
CC BY-SA 3.0
2016-08-05T19:53:48.670Z
I guess `.after('>= '~now)` should be `.eventDate('>= '~now)`, otherwise this looks solid.
Mats Mikkel Rummelhoff
CC BY-SA 3.0
2016-08-05T21:29:12.763Z
Yes!! Thanks! Using ".eventDate(...)" worked for me. Appreciate the help!!
dace
CC BY-SA 3.0
2016-08-05T19:04:01.657Z
2016-08-05T20:11:35.850Z
2016-08-05T20:11:35.850Z
Siebird
<p>Trying to pull in a limit of 2 events that are upcoming (so the event's eventDate should be newer than today). I currently have this: </p>

<pre><code>{% set entries = craft.entries.section('events').order('eventDate asc') %}
{% set today = now|date('Y-m-d') %} 

{% for event in entries %}
  {% if today &lt;= event.eventDate %}
    &lt;!-- markup here --&gt;
  {% endif %}
{% endfor %}
</code></pre>

<p>However, this returns all events that are upcoming. I would like to only limit it to 2. The problem when I put the .limit(2) on my for loop is that it chooses the first two (and those happen to be older events). Do I need to do another loop within the if statement and add .limit(2) to that or is there a better way?</p>

<p>Thanks!</p>

<entry>
Possible to filter an entry based on property?
# Possible to filter an entry based on property?

(Asked by: username_0 on 2016-08-05)

Trying to pull in a limit of 2 events that are upcoming (so the event's eventDate should be newer than today). I currently have this: 
{% set entries = craft.entries.section('events').order('eventDate asc') %}
{% set today = now|date('Y-m-d') %} 

{% for event in entries %}
  {% if today <= event.eventDate %}
    
  {% endif %}
{% endfor %}

However, this returns all events that are upcoming. I would like to only limit it to 2. The problem when I put the .limit(2) on my for loop is that it chooses the first two (and those happen to be older events). Do I need to do another loop within the if statement and add .limit(2) to that or is there a better way?
Thanks!

**Tags:** entry

---

## 1 answers

### Answer by username_1 on 2016-08-05. Score: 5 | Accepted answer

This should work below. Rather than querying all entries and looping through, just select the entries you need (ie. now) and limit them. 
{% set upcomingEvents = craft.entries.section('events').eventDate('>= '~now).limit(2) %}
{% for event in upcomingEvents %}
    
{% endfor %}

> **Comments:**
> **username_0**: Hi, thanks. Just tried this but its giving me a "Fatal error: Call to a member function getTimestamp() on boolean" with a large call stack table.  
> **username_0**: Should also clarify that the date I need to make sure it's displaying after today is the eventDate of the entry (a custom field I set) and not the published or posted date.  
> **username_2**: I guess `.after('>= '~now)` should be `.eventDate('>= '~now)`, otherwise this looks solid.  
> **username_0**: Yes!! Thanks! Using ".eventDate(...)" worked for me. Appreciate the help!!  

---

