title: Wordpress - $query, how to order users by lastname
body: <p>I am trying to change a query that gets users from the db and orders by user_nicename. I would like to sort the order of the users by surname. I have tried changing the ORDER BY the meta data value of last_name, but this didn't work.</p>
  
  <p>Here is the current bit of code that I am trying to change:</p>
  
  <pre><code>    global $wpdb;
  $query = "SELECT ID, user_nicename from $wpdb-&gt;users ORDER BY user_nicename";
  $author_ids = $wpdb-&gt;get_results($query);
  </code></pre>
  
  <p>Any tips or help would be greatly appreciated. I am new to PHP and and learning, but have found myself stumped by this problem.</p>
  
  <p>Many thanks</p>