Answers.Body: <p>I just noticed that you've posted an answer to your question already.</p>
  
  <p>Your approach using the <code>group</code> filter is probably all you need, as the <code>allDesigns</code> array is sorted by <code>postDate desc</code> and by using the <code>group</code> filter you'll keep that sort order, your author IDs and the nested entries will both be sorted by the design post date.</p>
  
  <p>To query the user models in the order of the IDs passed to the <code>id</code> param, you just need to add the <a href="https://craftcms.com/docs/templating/craft.users#fixedOrder" rel="nofollow"><code>fixedOrder</code></a> param to your <code>craft.users</code> criteria model.</p>
  
  <pre><code>{# Grab all the Design Entries #}
  {% set allDesigns = craft.entries.section('designs').limit(null).find() %}
  
  {# Group by the authorId #}
  {% set allDesignsByAuthorId = allDesigns|group('author.id') %}
  
  {# Grab all of the users with the userIds in allDesignsByAuthorId #}
  {% set designers = craft.users.group('designers').id(allDesignsByAuthorId|keys).fixedOrder(true) %}
  </code></pre>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2016-01-26T02:28:19.233Z
Answers.Text: Thanks or these options @carlcs! I will add the fixedOrder to this. :)
Answers.UserDisplayName: Angela
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2016-01-27T02:51:16.303Z
Answers.Text: I used the .fixedOrder(true) on the code above, and it is working on my local development site, but when I push to the live server, the page / section this is on seems to be stuck loading indefinitely with a blank screen. (Can't even view source code - it says "waiting...) Any ideas on what may be causing that?
Answers.UserDisplayName: Angela
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2016-01-27T03:01:40.220Z
Answers.Text: I think I found the issue in the PHP Error logs. Unfortunately the query is over the memory limit - http://cl.ly/3R0s140t2a33 - I haven't run into this issue before so any tips you can give would be appreciated. :) Thank you!
Answers.UserDisplayName: Angela
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2016-01-23T22:27:30.000Z
Answers.LastActivityDate: 2016-01-23T22:27:30.000Z
Answers.UserDisplayName: carlcs
Answers.Body: <p>You could do something like this: get all your designer users, loop them and for each user you try to get the latest design entry, if there exists one, merge it to a custom array which uses the post date of the entry as the key and the designer's user model as the value.</p>
  
  <p>You can now sort that array using the <a href="http://twig.sensiolabs.org/doc/filters/sort.html" rel="nofollow"><code>sort</code></a> filter, which sorts the array by its key.</p>
  
  <p>I should note that this approach creates a criteria model and calls the <code>first</code> method for each user, so it probably causes quite a number of database queries. That's why I recommend to add caching to the template or even think about getting the users with a custom plugin and SQL.</p>
  
  <pre><code>{% set designers = {} %}
  
  {% set users = craft.users.group('designers').limit(null) %}
  {% for user in users %}
  
      {% set latestDesign = craft.entries.section('designs').author(user).first() %}
      {% if latestDesign %}
          {% set designers = designers|merge({
              (latestDesign.postDate): user
          }) %}
      {% endif %}
  
  {% endfor %}
  
  {% for key, designer in designers|sort %}
      &lt;li&gt;{{ designer }} (Latest design posted: {{ key }})&lt;/li&gt; 
  {% endfor %}
  </code></pre>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2016-01-23T21:49:16.850Z
Answers.LastActivityDate: 2016-01-23T21:49:16.850Z
Answers.UserDisplayName: carlcs
Body: <p>I am trying to order a list of Users by the date of their last entry. order('postDate desc') works for entries of course, but I can't find a way to order the Users of those posts based on their latest post date. This is the code I am using now which orders the User by the date their account was created.    </p>
  
  <pre><code>{# Grab all the Design Entries #}
  {% set allDesigns = craft.entries.section('designs').limit(null).find() %}
  
  {# Group by the authorId #}
  {% set allDesignsByAuthorId = allDesigns|group('authorId') %}
  
  {# Grab all of the users with the userIds in allDesignsByAuthorId #}
  {% set designers = craft.users.group('designers').id(allDesignsByAuthorId|keys).order('dateCreated desc') %}
  </code></pre>
  
  <p>Thank you in advance for any help you can give! </p>
  
Tags: <entries><users><order>
Title: Order Users List by Last Entry Date
ThreadText: # Order Users List by Last Entry Date
  
  (Asked by: username_0 on 2016-01-23)
  
  I am trying to order a list of Users by the date of their last entry. order('postDate desc') works for entries of course, but I can't find a way to order the Users of those posts based on their latest post date. This is the code I am using now which orders the User by the date their account was created.
  
  ```
  {# Grab all the Design Entries #}
  {% set allDesigns = craft.entries.section('designs').limit(null).find() %}
  
  {# Group by the authorId #}
  {% set allDesignsByAuthorId = allDesigns|group('authorId') %}
  
  {# Grab all of the users with the userIds in allDesignsByAuthorId #}
  {% set designers = craft.users.group('designers').id(allDesignsByAuthorId|keys).order('dateCreated desc') %}
  
  ```
  
  Thank you in advance for any help you can give!
  
  **Tags:** entries, users, order
  
  
  ---
  
  ## 2 answers
  
  ### Answer by username_1 on 2016-01-23. Score: 2 | Accepted answer
  
  I just noticed that you've posted an answer to your question already.
  
  Your approach using the `group` filter is probably all you need, as the `allDesigns` array is sorted by `postDate desc` and by using the `group` filter you'll keep that sort order, your author IDs and the nested entries will both be sorted by the design post date.
  
  To query the user models in the order of the IDs passed to the `id` param, you just need to add the [`fixedOrder`](https://craftcms.com/docs/templating/craft.users#fixedOrder) param to your `craft.users` criteria model.
  
  ```
  {# Grab all the Design Entries #}
  {% set allDesigns = craft.entries.section('designs').limit(null).find() %}
  
  {# Group by the authorId #}
  {% set allDesignsByAuthorId = allDesigns|group('author.id') %}
  
  {# Grab all of the users with the userIds in allDesignsByAuthorId #}
  {% set designers = craft.users.group('designers').id(allDesignsByAuthorId|keys).fixedOrder(true) %}
  
  ```
  
  > **Comments:**
  > **username_0**: Thanks or these options @username_1! I will add the fixedOrder to this. :)  
  > **username_0**: I used the .fixedOrder(true) on the code above, and it is working on my local development site, but when I push to the live server, the page / section this is on seems to be stuck loading indefinitely with a blank screen. (Can't even view source code - it says "waiting...) Any ideas on what may be causing that?  
  > **username_0**: I think I found the issue in the PHP Error logs. Unfortunately the query is over the memory limit - http://cl.ly/3R0s140t2a33 - I haven't run into this issue before so any tips you can give would be appreciated. :) Thank you!  
  
  ---
  
  ### Answer by username_1 on 2016-01-23. Score: 1
  
  You could do something like this: get all your designer users, loop them and for each user you try to get the latest design entry, if there exists one, merge it to a custom array which uses the post date of the entry as the key and the designer's user model as the value.
  
  You can now sort that array using the [`sort`](http://twig.sensiolabs.org/doc/filters/sort.html) filter, which sorts the array by its key.
  
  I should note that this approach creates a criteria model and calls the `first` method for each user, so it probably causes quite a number of database queries. That's why I recommend to add caching to the template or even think about getting the users with a custom plugin and SQL.
  
  ```
  {% set designers = {} %}
  
  {% set users = craft.users.group('designers').limit(null) %}
  {% for user in users %}
  
      {% set latestDesign = craft.entries.section('designs').author(user).first() %}
      {% if latestDesign %}
          {% set designers = designers|merge({
              (latestDesign.postDate): user
          }) %}
      {% endif %}
  
  {% endfor %}
  
  {% for key, designer in designers|sort %}
      <li>{{ designer }} (Latest design posted: {{ key }})</li> 
  {% endfor %}
  
  ```
  
  
  ---
  
  