WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have narrowed the code down to this:

    $authors = $wpdb->get_results('SELECT DISTINCT post_author FROM '.$wpdb->posts);
    foreach($authors as $author):


I would like the authors to be sorted Alphabetically, it doesn't matter if it sorts by first name, last name.

share|improve this question
What do you want as an end result? A list of names, a list of author ids? – Douglas.Sesar Sep 12 '12 at 4:40
A list of names – Rocco Freer Sep 16 '12 at 7:41

Your Query gets the authors ID and is you want them sorted Alphabetically you will need to get the author(user object) so try:

$authors = $wpdb->get_results('SELECT DISTINCT post_author FROM '.$wpdb->posts);
    $users = get_users( array(
        'include' => $authors,
        'orderby' =>  'display_name'
    foreach ((array)$users as $user) {
       echo '<li>' . $user->display_name. '</li>';
share|improve this answer
There is no tag in the answer so your problem is not comming from here – Bainternet Sep 17 '12 at 8:27
Thanks, For your help – Rocco Freer Sep 28 '12 at 2:14

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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