11

Currently I am sorting the entries by an ID:

{% for gallery in craft.entries.section('Gallery').order('available desc').limit(none) %}

but I would like to show the latest entries on top, currently it shows available first but latest entries ones go to the bottom. How can I mix the above code with something like this?

.order('postDate desc') %}
2
  • At the risk of asking a stupid question, have you tried just chaining them? .order('this asc').order('that desc').limit(10). Just a hunch, but I can't test it out right now. Mar 19, 2015 at 16:30
  • I did... it only recognizes the last .order :( Mar 19, 2015 at 18:04

1 Answer 1

17

If you want to order by multiple columns that include custom fields, first make sure you're at least on Craft 2.4.2684, then you'll be able to use this syntax:

{% for gallery in craft.entries.section('Gallery').order('postDate desc, available desc').limit(null) %}

Also note that that you should be using limit(null) instead of limit(none) if you want to result all results.

5
  • For some reason the syntax you showed gives me an error CDbCommand failed to execute the SQL statement: SQLSTATE[42S22]: Column not found: 1054 Unknown column 'available' in 'order clause', but wen reversing the order it worked as expected :) .order('available desc, postDate desc') Mar 19, 2015 at 18:12
  • What's the error?
    – Brad Bell
    Mar 19, 2015 at 18:13
  • CDbCommand failed to execute the SQL statement: SQLSTATE[42S22]: Column not found: 1054 Unknown column 'available' in 'order clause' Mar 19, 2015 at 18:20
  • You have a custom field with an available handle in the field layout of your Gallery section?
    – Brad Bell
    Mar 19, 2015 at 22:25
  • Yes, I do have a custom field with a handle available Mar 20, 2015 at 23:19

Your Answer

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

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