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?

1 Answer 1

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"}
2
  • 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
    Commented Jan 26, 2013 at 12:04
  • GDmac: I thought of doing that, but I'm trying to make as few custom fields as I can...
    – Atle
    Commented Jan 30, 2013 at 14:13

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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