Title: More efficient author list code
Last modified: August 18, 2016

---

# More efficient author list code

 *  [bopuc](https://wordpress.org/support/users/bopuc/)
 * (@bopuc)
 * [20 years, 7 months ago](https://wordpress.org/support/topic/more-efficient-author-list-code/)
 * The built-in “list_authors” and “wp_list_authors” (which uses “list_authors”)
   is a resource sucking nightmare if you turn on the post count feature. A list
   of 30 authors with varying post counts from 1 to 489 was causing 134 hits to 
   the database *on every page load*. On a high volume site, this was killing the
   server. Not to mention the page generation time was up to 15 seconds.
 * So, I wrote my own. One single query to the database and page rendering is back
   down to a second. 🙂
    Unfortunately, I don’t have the time to package it up and
   host a plugin, but it was suggested I drop the code in here for others to use
   and adapt as they see fit. I hope that’s ok? :\
 * 
    // -------------------------------------------- // AUTHORS LISTING, with entry
   counts // -------------------------------------------- // function get_authors_info(){
   global $wpdb; $query = "SELECT DISTINCT U.ID AS user_id, user_nickname, user_firstname,
   user_lastname, user_nicename, COUNT(P.ID) AS user_count FROM $wpdb->users AS 
   U, $wpdb->posts AS P WHERE user_login <> 'admin' AND P.post_author = U.ID AND
   P.post_status = 'publish' GROUP BY U.ID ORDER BY user_firstname "; $authors =
   $wpdb->get_results($query); return $authors; } function authors_list() { $authors
   = get_authors_info(); foreach($authors as $author) { $cl .= "t<li>"; $cl .= '
   <a href="' . get_author_link(0, $author->ID, $author->user_nicename) . '" title
   ="Posts by '.wp_specialchars($author->user_nickname) . '">'; $cl .= $author->
   user_firstname . " " . $author->user_lastname; $cl .= "</a>&nbsp;<span class=\"
   listcount\">" . $author->user_count . "</span>"; $cl .= "</li>r"; } $authors_list
   = $cl; print $authors_list; } // called with authors_list(); // --------------------------------------------

Viewing 7 replies - 1 through 7 (of 7 total)

 *  [lookup](https://wordpress.org/support/users/lookup/)
 * (@lookup)
 * [20 years, 7 months ago](https://wordpress.org/support/topic/more-efficient-author-list-code/#post-269241)
 * Great work!! My modified version:
 * function authors_list() {
    $authors = get_authors_info(); foreach($authors as
   $author) { $cl .= ”
    - “;
       $cl .= ‘ID, $author->user_nicename) . ‘” title=”‘.wp_specialchars($author-
      >user_nickname) .” å?‘è¡¨çš„æ–‡ç« ” . ‘”>’; $cl .= wp_specialchars($author-
      >user_nickname); $cl .= “ <span class=\”listcount\”>” . “(” . $author->user_count.“)”.“
      </span>”; $cl .= “
    - “;
       } $authors_list = $cl; print $authors_list; }
 *  [moshu](https://wordpress.org/support/users/moshu/)
 * (@moshu)
 * [20 years, 7 months ago](https://wordpress.org/support/topic/more-efficient-author-list-code/#post-269242)
 * If you put the code in between backticks (check out the instructions below the
   text input area!) others might be able to use your code 🙂
 *  Thread Starter [bopuc](https://wordpress.org/support/users/bopuc/)
 * (@bopuc)
 * [20 years, 7 months ago](https://wordpress.org/support/topic/more-efficient-author-list-code/#post-269249)
 * I did. 😉
 *  [chuggins](https://wordpress.org/support/users/chuggins/)
 * (@chuggins)
 * [20 years ago](https://wordpress.org/support/topic/more-efficient-author-list-code/#post-269356)
 * Maybe this is a stupid question: But how would one incorporate this code into
   their wordpress blog (i.e., step by step)? I’m a pretty basic user: I can install
   plugins, and copy and paste into a template, but I’m not quite sure what I would
   do with this code.
 *  [akudless](https://wordpress.org/support/users/akudless/)
 * (@akudless)
 * [19 years, 8 months ago](https://wordpress.org/support/topic/more-efficient-author-list-code/#post-269357)
 * I’m new like chuggins above. Could someone help out with more details instructions
   on how to use this code?
    Thanks
 *  [zefefre](https://wordpress.org/support/users/zefefre/)
 * (@zefefre)
 * [19 years, 7 months ago](https://wordpress.org/support/topic/more-efficient-author-list-code/#post-269361)
 * Does anyone has any idea how to list authors based on their post count?
 *  [zefefre](https://wordpress.org/support/users/zefefre/)
 * (@zefefre)
 * [19 years, 7 months ago](https://wordpress.org/support/topic/more-efficient-author-list-code/#post-269362)
 * Oh I just figured it out, thank you for the code!
 * [@chuggins](https://wordpress.org/support/users/chuggins/) & akudless
    You should
   add the code to template-functions-author.php and call the function from your
   template/theme file. The code need some modification though to make it works 
   with latest version of wordpress.

Viewing 7 replies - 1 through 7 (of 7 total)

The topic ‘More efficient author list code’ is closed to new replies.

## Tags

 * [author](https://wordpress.org/support/topic-tag/author/)

 * 7 replies
 * 6 participants
 * Last reply from: [zefefre](https://wordpress.org/support/users/zefefre/)
 * Last activity: [19 years, 7 months ago](https://wordpress.org/support/topic/more-efficient-author-list-code/#post-269362)
 * Status: not a support question

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
