3

I've got an events listings which works pretty well and there is a:

  • Custom Date field, eventEnd (just date)
  • Custom Start Time, eventStart (just time)
  • Custom End Time, eventEnd (just time)

I can list these entries so we list by date then time by using:

{% for entry in craft.entries.section('events').order('eventDate', 'eventStart').find() %}

but eventStart is ignored altogether, even when I would use:

{% for entry in craft.entries.section('events').order('eventStart').find() %}

I would expect:

Event 1: 14:00 Event 2: 15:00 Event 3: 16:00

but instead get something more random based I think on post date.

Suggestions welcome thank you!

UPDATE:

my biggest issue is actually being able to list by eventStart at all. Just using {{ eventStart }} reveals the current date. But if I try to boil down to just the hour, it's not a recognised way of ordering (even though it's just a set of numbers?)

So, I'm not sure where to head with this. I'm sure that if my start time was bundled in with the main date, all would be fine, but it makes the system a bit less obvious and flexible.

Here's what I've tried:

{% set completeeventlist = craft.entries.section('events') %}
{% for x in craft.entries(completeeventlist).order('eventDate') %}
<ul>
    {% set es = x.eventStart|date('H') %}
        {% for entry in craft.entries(x).order(es) %}
        <li>{{ entry.id }}{{ es }}</li>
    {% endfor %}
</ul>
{% endfor %}
  • Have you tried: {% for entry in craft.entries.section('events').order('eventDate, eventStart').find() %} – Luke Holder Jan 15 '15 at 11:45
  • Tried that - throws an error CDbCommand failed to execute the SQL statement: SQLSTATE[42S22]: Column not found: 1054 Unknown column 'eventStart' in 'order clause' – Simon Clayson Jan 15 '15 at 13:58
  • eventStart is defiantly there, just ignored though as something to order from. – Simon Clayson Jan 15 '15 at 14:00
  • is it a custom fieldType from a plugin? – Luke Holder Jan 15 '15 at 14:50
  • No, just a normal datetime field. It's a custom field, but it's just the time. – Simon Clayson Jan 15 '15 at 19:09
4

Craft always saves a complete DateTime value to the database, even if you only make it set / show the time part of it in the Control Panel.

To ignore the date part (which in this case is set to the day you saved your entry) within the order parameter, you can make use of the time() MySQL function:

{% set entries = craft.entries.section('events').order('eventDate', 'time(eventStart)') %}
  • That "time()" function inside the order did the trick for me. Couldn't figure out why it couldn't order correctly from a time field. – Ole Jan 21 '16 at 13:14

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.