Answers.Body: <p>If you want to order by multiple columns that include custom fields, first make sure you're at least on <a href="http://buildwithcraft.com/updates#build2684" rel="noreferrer">Craft 2.4.2684</a>, then you'll be able to use this syntax:</p>
  
  <pre><code>{% for gallery in craft.entries.section('Gallery').order('postDate desc, available desc').limit(null) %}
  </code></pre>
  
  <p>Also note that that you should be using <code>limit(null)</code> instead of <code>limit(none)</code> if you want to result all results.</p>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-03-19T18:12:25.107Z
Answers.Text: 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')`
Answers.UserDisplayName: Ricardo Henriquez
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-03-19T18:13:26.080Z
Answers.Text: What's the error?
Answers.UserDisplayName: Brad Bell
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-03-19T18:20:04.547Z
Answers.Text: `CDbCommand failed to execute the SQL statement: SQLSTATE[42S22]: Column not found: 1054 Unknown column 'available' in 'order clause'`
Answers.UserDisplayName: Ricardo Henriquez
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-03-19T22:25:31.777Z
Answers.Text: You have a custom field with an `available` handle in the field layout of your `Gallery` section?
Answers.UserDisplayName: Brad Bell
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-03-20T23:19:13.043Z
Answers.Text: Yes, I do have a custom field with a handle available
Answers.UserDisplayName: Ricardo Henriquez
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-03-19T17:21:15.680Z
Answers.LastActivityDate: 2015-09-01T08:56:38.297Z
Answers.LastEditDate: 2015-09-01T08:56:38.297Z
Answers.UserDisplayName: Brad Bell
Body: <p>Currently I am sorting the entries by an ID:</p>
  
  <pre><code>{% for gallery in craft.entries.section('Gallery').order('available desc').limit(none) %}
  </code></pre>
  
  <p>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?</p>
  
  <pre><code>.order('postDate desc') %}
  </code></pre>
  
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2015-03-19T16:30:41.207Z
Comments.Text: 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.
Comments.UserDisplayName: Stephen Lewis
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2015-03-19T18:04:43.813Z
Comments.Text: I did... it only recognizes the last .order :(
Comments.UserDisplayName: Ricardo Henriquez
Tags: <templating><entries><sorting>
Title: How do I sort entries by two variables?
ThreadText: # How do I sort entries by two variables?
  
  (Asked by: username_0 on 2015-03-19)
  
  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') %}
  
  ```
  
  **Tags:** templating, entries, sorting
  
  > **Comments:**
  > **username_1**: 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.  
  > **username_0**: I did... it only recognizes the last .order :(  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_2 on 2015-03-19. Score: 18 | Accepted answer
  
  If you want to order by multiple columns that include custom fields, first make sure you're at least on [Craft 2.4.2684](http://buildwithcraft.com/updates#build2684), 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.
  
  > **Comments:**
  > **username_0**: 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')`  
  > **username_2**: What's the error?  
  > **username_0**: `CDbCommand failed to execute the SQL statement: SQLSTATE[42S22]: Column not found: 1054 Unknown column 'available' in 'order clause'`  
  > **username_2**: You have a custom field with an `available` handle in the field layout of your `Gallery` section?  
  > **username_0**: Yes, I do have a custom field with a handle available  
  
  ---
  
  