2

I'm listing courses by a custom date field, but some courses are "on demand" and doesn't have a specific time. When using orderby="custom_field" and sort="asc" all the courses without a date shows up first in the list. How can I get them to show up at the end instead?

3

You may have to run two Channel Entries loops to do this, since the empty fields are essentially treated as 0, so they will always come first in an ascending order.

First, to get your entries which have a custom date:

{exp:channel:entries channel=:courses" orderby="course_date" sort="asc" search:course_date="not IS_EMPTY"}

Then grab those which do not have a custom date:

{exp:channel:entries channel="courses" orderby="title" sort="asc" search:course_date="IS_EMPTY"}
| improve this answer | |
  • 1
    (As always Derek has a nice solution, which i like to extend :-) . Since the OP (original poster) mentions "some courses are on demand", So, why not have a checkbox/select to indicate if a course is "on demand" (e.g. has a datetime filled in), then with one channel entries loop orderby="on_demand|course_date" sort="desc|asc" (edit: the on_demand variable needs to be 1 for regular courses so they show up first) – GDmac Jan 26 '13 at 12:04
  • GDmac: I thought of doing that, but I'm trying to make as few custom fields as I can... – Atle Jan 30 '13 at 14:13

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.