ExpressionEngine CMS
Open, Free, Amazing

Thread

This is an archived forum and the content is probably no longer relevant, but is provided here for posterity.

The active forums are here.

Limit entries after date conditional

July 20, 2012 3:13pm

Subscribe [1]
  • #1 / Jul 20, 2012 3:13pm

    I am struggling to find a way to limit the number of results published in a custom field {event_date} is greater than {current_time}. The simple code I tried to use was:

    {exp:channel:entries
    channel="events"
    disable="category_fields|member_data|trackbacks|pagination"
    dynamic="no"
    orderby="event_date"
    sort="asc"
    limit="3"
    }
     {if event_date >= current_time}
      <h2>{title}</h2>
    <p> {/if}    <br />
    {/exp:channel:entries}

    The problem is that the limit parameter loops through 3 entries that do not meet the conditional requirements and then stops looking for results, so nothing gets published.

    If it weren’t a date issue I could use the search= parameter, but since I need to compare it to current_time, that doesn’t work.

    Any thoughts on how I can achieve this? It is probably something obvious, but I’ve been thinking about it too long and am lost in the logic forest now.

    Any help is appreciated.

     

  • #2 / Jul 23, 2012 11:53am

    Dan Decker

    7338 posts

    Hi The Nimble Agency,

    As you’ve discovered, the entries tag pair is going to grab 3 entries based on the criteria in the parameters, *then* apply your comparison.

    I’m having a tough time working out the logic as well, which leads me to ask: can you set the entry date to the event date and eliminate the event_date field?

    If you did that, you could take advantage of the start_on= and show_future_entries= parameters:

    {exp:channel:entries
     channel="events"
     disable="category_fields|member_data|pagination"
     dynamic="no"
     sort="asc"
     limit="3" start_on="{current_time format='%Y-%m-%d %H:%i'}" show_future_entries="yes"}
      <h2>{title}</h2><p>  <br />
    {/exp:channel:entries}

    Let me know what you think.

    Cheers,

  • #3 / Jul 23, 2012 11:57am

    Thanks Dan. I have done that in the past, but changed to this method because clients would get confused about why entry_date meant one thing for their blog, but another thing for Events.

    I actually just went and bought Low Events to solve the problem with an add-on. Reduces client confusion.

  • #4 / Jul 24, 2012 11:07am

    Dan Decker

    7338 posts

    Hi The Nimble Agency,

    I totally understand the “client confusion” position.

    Low Events looks great, and dead-simple.

    Is there anything else I can assist you with?

    Cheers,

.(JavaScript must be enabled to view this email address)

ExpressionEngine News!

#eecms, #events, #releases