diff --git a/wp-admin/edit-pages.php b/wp-admin/edit-pages.php
index db44ae967c..4ea84145ef 100644
--- a/wp-admin/edit-pages.php
+++ b/wp-admin/edit-pages.php
@@ -45,18 +45,18 @@ printf( _c( '%1$s%2$s%3$s|You can reorder these: 1: Pages, 2: by {s}, 3: matchin
$avail_post_stati = get_available_post_statuses('page');
$status_links = array();
+$num_posts = wp_count_posts('page');
foreach ( $post_stati as $status => $label ) {
$class = '';
if ( !in_array($status, $avail_post_stati) )
continue;
-
- $num_posts = wp_count_posts('page', $status);
+
if ( $status == $_GET['post_status'] )
$class = ' class="current"';
$status_links[] = "
" .
- sprintf($label[2], $num_posts) . '';
+ sprintf($label[2], $num_posts->$status) . '';
}
$class = empty($_GET['post_status']) ? ' class="current"' : '';
$status_links[] = "All Pages";
diff --git a/wp-admin/edit.php b/wp-admin/edit.php
index ccf01f7b41..d0895fad8c 100644
--- a/wp-admin/edit.php
+++ b/wp-admin/edit.php
@@ -52,18 +52,18 @@ if ( is_single() ) {
$label ) {
$class = '';
if ( !in_array($status, $avail_post_stati) )
continue;
- $num_posts = wp_count_posts('post', $status);
if ( $status == $_GET['post_status'] )
$class = ' class="current"';
$status_links[] = "- " .
- sprintf($label[2], $num_posts) . '';
+ sprintf($label[2], $num_posts->$status) . '';
}
$class = empty($_GET['post_status']) ? ' class="current"' : '';
$status_links[] = "
- All Posts";
diff --git a/wp-admin/index.php b/wp-admin/index.php
index 034d68e38f..fdb7dda20b 100644
--- a/wp-admin/index.php
+++ b/wp-admin/index.php
@@ -37,15 +37,8 @@ $today = current_time('mysql', 1);
get_var("SELECT COUNT(*) FROM $wpdb->comments WHERE comment_approved = '1'");
+$num_posts = wp_count_posts( 'post' );
+$num_pages = wp_count_posts( 'page' );
$num_cats = wp_count_terms('category');
@@ -53,17 +46,17 @@ $num_tags = wp_count_terms('post_tag');
$post_type_texts = array();
-if ( $num_posts ) {
- $post_type_texts[] = ''.sprintf( __ngettext( '%s post', '%s posts', $num_posts ), number_format_i18n( $num_posts ) ).'';
+if ( !empty($num_posts->publish) ) {
+ $post_type_texts[] = ''.sprintf( __ngettext( '%s post', '%s posts', $num_posts->publish ), number_format_i18n( $num_posts->publish ) ).'';
}
-if ( $num_pages ) {
- $post_type_texts[] = ''.sprintf( __ngettext( '%s page', '%s pages', $num_pages ), number_format_i18n( $num_pages ) ).'';
+if ( !empty($num_pages->publish) ) {
+ $post_type_texts[] = ''.sprintf( __ngettext( '%s page', '%s pages', $num_pages->publish ), number_format_i18n( $num_pages->publish ) ).'';
}
-if ( $num_drafts ) {
- $post_type_texts[] = ''.sprintf( __ngettext( '%s draft', '%s drafts', $num_drafts ), number_format_i18n( $num_drafts ) ).'';
+if ( !empty($num_posts->draft) ) {
+ $post_type_texts[] = ''.sprintf( __ngettext( '%s draft', '%s drafts', $num_posts->draft ), number_format_i18n( $num_posts->draft ) ).'';
}
-if ( $num_future ) {
- $post_type_texts[] = ''.sprintf( __ngettext( '%s scheduled post', '%s scheduled posts', $num_future ), number_format_i18n( $num_future ) ).'';
+if ( !empty($num_posts->future) ) {
+ $post_type_texts[] = ''.sprintf( __ngettext( '%s scheduled post', '%s scheduled posts', $num_posts->future ), number_format_i18n( $num_posts->future ) ).'';
}
$cats_text = ''.sprintf( __ngettext( '%s category', '%s categories', $num_cats ), number_format_i18n( $num_cats ) ).'';
diff --git a/wp-includes/post.php b/wp-includes/post.php
index 4795f3d639..93cc19f7bd 100644
--- a/wp-includes/post.php
+++ b/wp-includes/post.php
@@ -782,7 +782,7 @@ function sanitize_post_field($field, $value, $post_id, $context) {
}
/**
- * wp_count_posts() - Count number of posts with a given type and status
+ * wp_count_posts() - Count number of posts with a given type
*
* {@internal Missing Long Description}}
*
@@ -791,13 +791,19 @@ function sanitize_post_field($field, $value, $post_id, $context) {
* @since 2.5
*
* @param string $type Post type
- * @param string $status Post status
- * @return int Number of posts
+ * @return array Number of posts for each status
*/
-function wp_count_posts( $type = 'post', $status = 'publish' ) {
+function wp_count_posts( $type = 'post' ) {
global $wpdb;
- return $wpdb->get_var( $wpdb->prepare("SELECT COUNT(*) FROM $wpdb->posts WHERE post_type = %s AND post_status = %s", $type, $status) );
+ $count = $wpdb->get_results( $wpdb->prepare( "SELECT post_status, COUNT( * ) AS num_posts FROM {$wpdb->posts} WHERE post_type = %s GROUP BY post_status", $type ), ARRAY_A );
+
+ $stats = array( );
+ foreach( (array) $count as $row_num => $row ) {
+ $stats[$row['post_status']] = $row['num_posts'];
+ }
+
+ return (object) $stats;
}
/**