10

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') %}
  • 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. – Stephen Lewis Mar 19 '15 at 16:30
  • I did... it only recognizes the last .order :( – Ricardo Henriquez Mar 19 '15 at 18:04
15

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.

  • 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') – Ricardo Henriquez Mar 19 '15 at 18:12
  • What's the error? – Brad Bell Mar 19 '15 at 18:13
  • CDbCommand failed to execute the SQL statement: SQLSTATE[42S22]: Column not found: 1054 Unknown column 'available' in 'order clause' – Ricardo Henriquez Mar 19 '15 at 18:20
  • You have a custom field with an available handle in the field layout of your Gallery section? – Brad Bell Mar 19 '15 at 22:25
  • Yes, I do have a custom field with a handle available – Ricardo Henriquez Mar 20 '15 at 23:19

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.