From 9f0ebcd37ea4f7ddfba71f1a5dc03619d35286ce Mon Sep 17 00:00:00 2001 From: rob1n Date: Thu, 29 Mar 2007 01:39:05 +0000 Subject: [PATCH] Speed (wp_)list_authors by consolidating some queries. Props graeme. fixes #1659 git-svn-id: https://develop.svn.wordpress.org/trunk@5135 602fd350-edb4-49c9-b593-d223f7449a82 --- wp-includes/author-template.php | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/wp-includes/author-template.php b/wp-includes/author-template.php index 9502814952..20fe79ce22 100644 --- a/wp-includes/author-template.php +++ b/wp-includes/author-template.php @@ -173,6 +173,8 @@ function get_author_name( $auth_id ) { } function wp_list_authors($args = '') { + global $wpdb; + if ( is_array($args) ) $r = &$args; else @@ -182,15 +184,18 @@ function wp_list_authors($args = '') { 'feed' => '', 'feed_image' => ''); $r = array_merge($defaults, $r); extract($r); - - global $wpdb; + // TODO: Move select to get_authors(). - $query = "SELECT ID, user_nicename from $wpdb->users " . ($exclude_admin ? "WHERE user_login <> 'admin' " : '') . "ORDER BY display_name"; - $authors = $wpdb->get_results($query); + $authors = $wpdb->get_results("SELECT ID, user_nicename from $wpdb->users " . ($exclude_admin ? "WHERE user_login <> 'admin' " : '') . "ORDER BY display_name"); + + $author_count = array(); + foreach ((array) $wpdb->get_results("SELECT DISTINCT post_author, COUNT(ID) AS count FROM $wpdb->posts WHERE post_status = 'publish' GROUP BY post_author") as $row) { + $author_count[$row->post_author] = $row->count; + } foreach ( (array) $authors as $author ) { $author = get_userdata( $author->ID ); - $posts = get_usernumposts($author->ID); + $posts = (isset($author_count[$author->ID])) ? $author_count[$author->ID] : 0; $name = $author->nickname; if ( $show_fullname && ($author->first_name != '' && $author->last_name != '') )