Ticket #30928: 30928.patch
File 30928.patch, 1.5 KB (added by , 10 years ago) |
---|
-
src/wp-includes/post.php
2351 2351 2352 2352 $cache_key = _count_posts_cache_key( $type, $perm ); 2353 2353 2354 $counts = wp_cache_get( $cache_key, 'counts' ); 2355 if ( $counts ) { 2356 /** This filter is documented in wp-includes/post.php */ 2357 return apply_filters( 'wp_count_posts', $counts, $type, $perm ); 2358 } 2359 2354 2360 $query = "SELECT post_status, COUNT( * ) AS num_posts FROM {$wpdb->posts} WHERE post_type = %s"; 2355 2361 if ( 'readable' == $perm && is_user_logged_in() ) { 2356 2362 $post_type_object = get_post_type_object($type); … … 2362 2368 } 2363 2369 $query .= ' GROUP BY post_status'; 2364 2370 2365 $counts = wp_cache_get( $cache_key, 'counts' ); 2366 if ( false === $counts ) { 2367 $results = (array) $wpdb->get_results( $wpdb->prepare( $query, $type ), ARRAY_A ); 2368 $counts = array_fill_keys( get_post_stati(), 0 ); 2371 $results = (array) $wpdb->get_results( $wpdb->prepare( $query, $type ), ARRAY_A ); 2372 $counts = array_fill_keys( get_post_stati(), 0 ); 2369 2373 2370 foreach ( $results as $row ) 2371 $counts[ $row['post_status'] ] = $row['num_posts']; 2372 2373 $counts = (object) $counts; 2374 wp_cache_set( $cache_key, $counts, 'counts' ); 2374 foreach ( $results as $row ) { 2375 $counts[ $row['post_status'] ] = $row['num_posts']; 2375 2376 } 2376 2377 2378 $counts = (object) $counts; 2379 wp_cache_set( $cache_key, $counts, 'counts' ); 2380 2377 2381 /** 2378 2382 * Modify returned post counts by status for the current post type. 2379 2383 *