WordPress.org

Make WordPress Core

Changeset 6730


Ignore:
Timestamp:
02/05/2008 07:08:14 PM (12 years ago)
Author:
ryan
Message:

Add wp_count_posts().

Location:
trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/wp-admin/index.php

    r6705 r6730  
    3838
    3939<?php
    40 $num_posts = $wpdb->get_var( "SELECT COUNT(*) FROM $wpdb->posts WHERE post_type = 'post' AND post_status = 'publish'" );
     40$num_posts = wp_count_posts('post', 'publish');
    4141
    42 $num_pages = $wpdb->get_var( "SELECT COUNT(*) FROM $wpdb->posts WHERE post_type = 'page' AND post_status = 'publish'" );
     42$num_pages = wp_count_posts('page', 'publish');
    4343
    44 $num_drafts = $wpdb->get_var( "SELECT COUNT(*) FROM $wpdb->posts WHERE post_type = 'post' AND post_status = 'draft'" );
     44$num_drafts = wp_count_posts('post', 'draft');
    4545
    46 $num_future = $wpdb->get_var( "SELECT COUNT(*) FROM $wpdb->posts WHERE post_type = 'post' AND post_status = 'future'" );
     46$num_future = wp_count_posts('post', 'future');
    4747
    4848$num_comments = $wpdb->get_var("SELECT COUNT(*) FROM $wpdb->comments WHERE comment_approved = '1'");
  • trunk/wp-includes/post.php

    r6726 r6730  
    791791
    792792/**
     793 * wp_count_posts() - Count number of posts with a given type and status
     794 *
     795 * {@internal Missing Long Description}}
     796 *
     797 * @package WordPress
     798 * @subpackage Post
     799 * @since 2.5
     800 *
     801 * @param string $type Post type
     802 * @param string $status Post status
     803 * @return int Number of posts
     804 */
     805function wp_count_posts( $type = 'post', $status = 'publish' ) {
     806    global $wpdb;
     807
     808    return $wpdb->get_var( $wpdb->prepare("SELECT COUNT(*) FROM $wpdb->posts WHERE post_type = %s AND post_status = %s", $type, $status) );
     809}
     810
     811/**
    793812 * wp_delete_post() - Deletes a Post
    794813 *
Note: See TracChangeset for help on using the changeset viewer.