0

Have

  • events channel
  • have 10 entries
  • have a date field called event_start_date

Desire - display only up coming events in asc order

List

  • 2016-12-06
  • 2016-11-01
  • 2016-10-24
  • 2016-05-30
  • 2016-09-12
  • 2016-05-15
  • 2016-05-02
  • 2016-03-29
  • 2016-03-01
  • 2016-02-08

Code:

{exp:channel:entries channel="events" orderby="event_start_date" sort="asc"}
  {if {event_start_date format='%Y-%m-%d'} >= {current_time format='%Y-%m-%d'}}
    {event_start_date format='%Y-%m-%d'}<br>
  {/if}
{/exp:channel:entries}

Results:

2016-02-08
2016-03-01
2016-03-29
2016-05-02
2016-05-15
2016-05-30
2016-09-12
2016-10-24
2016-11-01
2016-12-06

Desired

2016-05-15
2016-05-30
2016-09-12
2016-10-24
2016-11-01
2016-12-06

What am i doing wrong?

Final working code:

{exp:channel:entries channel="events" orderby="event_start_date" sort="asc" search:event_start_date=">={current_time}"}
    {event_start_date format='%Y-%m-%d'}<br>
{/exp:channel:entries}
0

Try using the search parameter - https://docs.expressionengine.com/v2/add-ons/channel/channel_entries.html#search-field-name

search:event_start_date=">={current_time}"

How are you storing your date field? unix, mysql??

| improve this answer | |
  • thanks! that search on was exactly what i was looking for. – Lacer May 16 '16 at 23:01
0

It would be much simpler if you were to use the EE default {entry_date} that way you could use start_on= with show_future_entries="yes":

{exp:channel:entries channel="events" start_on="{current_time}" orderby="date" show_future_entries="yes"}
...
{/exp:channel:entries}

As per the documentation

Your current use of a custom field will return, lets say 30 entries and then you'll subsequently have to query, each of those 30 entries, one at a time, if this fields value is greater then the current date - all of which is an expensive DB/EE operation.

PS. Your conditional, is trying to compare a string that includes operators it should be just numbers. Try removing the format= part from your tag.

| improve this answer | |
  • thank you for the reply. Unfortunately using the entry date doesn't work in this scenario since it's an upcoming dates scenario. it would require people to modify 2 fields rather than just one. – Lacer May 16 '16 at 23:02
  • Yet if you remove the custom date field and stick with the standard entry_date field - users will only alter one field. Just code your templates with show_future_entries='yes' and it's done. – stuartmcd69 May 16 '16 at 23:56

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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