Ticket #17019: 17019.4.diff
File 17019.4.diff, 3.1 KB (added by , 11 years ago) |
---|
-
src/wp-admin/includes/class-wp-media-list-table.php
42 42 } 43 43 44 44 function get_views() { 45 global $ wpdb, $post_mime_types, $avail_post_mime_types;45 global $post_mime_types, $avail_post_mime_types; 46 46 47 47 $type_links = array(); 48 48 $_num_posts = (array) wp_count_attachments(); 49 49 $_total_posts = array_sum($_num_posts) - $_num_posts['trash']; 50 $total_orphans = $wpdb->get_var( "SELECT COUNT( * ) FROM $wpdb->posts WHERE post_type = 'attachment' AND post_status != 'trash' AND post_parent < 1" ); 50 51 $args = array( 52 'fields' => 'count', 53 'post_type' => 'attachment', 54 'post_status' => 'any', 55 'post_parent' => 0, 56 'suppress_filters' => false, 57 'query_context' => 'attachment_orphans_count', 58 ); 59 $total_orphans = (int) get_posts( $args ); 60 51 61 $matches = wp_match_mime_types(array_keys($post_mime_types), array_keys($_num_posts)); 52 62 foreach ( $matches as $type => $reals ) 53 63 foreach ( $reals as $real ) -
src/wp-admin/includes/media.php
40 40 * @return array $tabs with gallery if post has image attachment 41 41 */ 42 42 function update_gallery_tab($tabs) { 43 global $wpdb;44 45 43 if ( !isset($_REQUEST['post_id']) ) { 46 44 unset($tabs['gallery']); 47 45 return $tabs; … … 49 47 50 48 $post_id = intval($_REQUEST['post_id']); 51 49 52 if ( $post_id ) 53 $attachments = intval( $wpdb->get_var( $wpdb->prepare( "SELECT count(*) FROM $wpdb->posts WHERE post_type = 'attachment' AND post_status != 'trash' AND post_parent = %d", $post_id ) ) ); 50 if ( $post_id ) { 51 $args = array( 52 'fields' => 'count', 53 'post_type' => 'attachment', 54 'post_status' => 'any', 55 'post_parent' => $post_id, 56 'suppress_filters' => false, 57 'query_context' => 'gallery_attachment_count', 58 ); 59 $attachments = (int) get_posts( $args ); 60 } 54 61 55 62 if ( empty($attachments) ) { 56 63 unset($tabs['gallery']); -
src/wp-includes/query.php
1423 1423 , 'sentence' 1424 1424 , 'fields' 1425 1425 , 'menu_order' 1426 , 'query_context' 1426 1427 ); 1427 1428 1428 1429 foreach ( $keys as $key ) { … … 2271 2272 case 'id=>parent': 2272 2273 $fields = "$wpdb->posts.ID, $wpdb->posts.post_parent"; 2273 2274 break; 2275 case 'count': 2276 $fields = "COUNT(*)"; 2277 break; 2274 2278 default: 2275 2279 $fields = "$wpdb->posts.*"; 2276 2280 } … … 2924 2928 return $r; 2925 2929 } 2926 2930 2931 if ( 'count' == $q['fields'] ) { 2932 $this->posts = $wpdb->get_var( $this->request ); 2933 return $this->posts; 2934 } 2935 2927 2936 $split_the_query = ( $old_request == $this->request && "$wpdb->posts.*" == $fields && !empty( $limits ) && $q['posts_per_page'] < 500 ); 2928 2937 $split_the_query = apply_filters( 'split_the_query', $split_the_query, $this ); 2929 2938