diff --git a/wp-admin/index.php b/wp-admin/index.php index 48989a18a8..d23b9dbb64 100644 --- a/wp-admin/index.php +++ b/wp-admin/index.php @@ -37,13 +37,13 @@ $today = current_time('mysql', 1);

get_var( "SELECT COUNT(*) FROM $wpdb->posts WHERE post_type = 'post' AND post_status = 'publish'" ); +$num_posts = wp_count_posts('post', 'publish'); -$num_pages = $wpdb->get_var( "SELECT COUNT(*) FROM $wpdb->posts WHERE post_type = 'page' AND post_status = 'publish'" ); +$num_pages = wp_count_posts('page', 'publish'); -$num_drafts = $wpdb->get_var( "SELECT COUNT(*) FROM $wpdb->posts WHERE post_type = 'post' AND post_status = 'draft'" ); +$num_drafts = wp_count_posts('post', 'draft'); -$num_future = $wpdb->get_var( "SELECT COUNT(*) FROM $wpdb->posts WHERE post_type = 'post' AND post_status = 'future'" ); +$num_future = wp_count_posts('post', 'future'); $num_comments = $wpdb->get_var("SELECT COUNT(*) FROM $wpdb->comments WHERE comment_approved = '1'"); diff --git a/wp-includes/post.php b/wp-includes/post.php index 923d943b22..193c7c256c 100644 --- a/wp-includes/post.php +++ b/wp-includes/post.php @@ -789,6 +789,25 @@ function sanitize_post_field($field, $value, $post_id, $context) { return $value; } +/** + * wp_count_posts() - Count number of posts with a given type and status + * + * {@internal Missing Long Description}} + * + * @package WordPress + * @subpackage Post + * @since 2.5 + * + * @param string $type Post type + * @param string $status Post status + * @return int Number of posts + */ +function wp_count_posts( $type = 'post', $status = 'publish' ) { + global $wpdb; + + return $wpdb->get_var( $wpdb->prepare("SELECT COUNT(*) FROM $wpdb->posts WHERE post_type = %s AND post_status = %s", $type, $status) ); +} + /** * wp_delete_post() - Deletes a Post *