WordPress.org

Make WordPress Core

Ticket #5820: wp-includes-post.php.diff

File wp-includes-post.php.diff, 1.1 KB (added by josephscott, 6 years ago)
  • post.php

     
    790790} 
    791791 
    792792/** 
    793  * wp_count_posts() - Count number of posts with a given type and status 
     793 * wp_count_posts() - Count number of posts with a given type 
    794794 * 
    795795 * {@internal Missing Long Description}} 
    796796 * 
     
    799799 * @since 2.5 
    800800 * 
    801801 * @param string $type Post type 
    802  * @param string $status Post status 
    803  * @return int Number of posts 
     802 * @return array Number of posts for each status 
    804803 */ 
    805 function wp_count_posts( $type = 'post', $status = 'publish' ) { 
     804function wp_count_posts( $type = 'post' ) { 
    806805        global $wpdb; 
    807806 
    808         return $wpdb->get_var( $wpdb->prepare("SELECT COUNT(*) FROM $wpdb->posts WHERE post_type = %s AND post_status = %s", $type, $status) ); 
     807        $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 ); 
     808 
     809        $stats = array( ); 
     810        foreach( (array) $count as $row_num => $row ) { 
     811                $stats[$row['post_status']] = $row['num_posts']; 
     812        } 
     813 
     814        return $stats; 
    809815} 
    810816 
    811817/**