Ticket #17019: 17019.diff
File 17019.diff, 2.8 KB (added by , 13 years ago) |
---|
-
wp-admin/includes/class-wp-media-list-table.php
46 46 $type_links = array(); 47 47 $_num_posts = (array) wp_count_attachments(); 48 48 $_total_posts = array_sum($_num_posts) - $_num_posts['trash']; 49 if ( !isset( $total_orphans ) ) 50 $total_orphans = $wpdb->get_var( "SELECT COUNT( * ) FROM $wpdb->posts WHERE post_type = 'attachment' AND post_status != 'trash' AND post_parent < 1" ); 49 if ( !isset( $total_orphans ) ) { 50 $args = array( 51 'fields' => 'count', 52 'post_type' => 'attachment', 53 'post_status' => 'any', 54 'post_parent' => 0, 55 'suppress_filters' => false, 56 'query_context' => 'attachment_orphans_count', 57 ); 58 59 $total_orphans = intval( get_posts( $args ) ); 60 } 61 51 62 $matches = wp_match_mime_types(array_keys($post_mime_types), array_keys($_num_posts)); 52 63 foreach ( $matches as $type => $reals ) 53 64 foreach ( $reals as $real ) -
wp-admin/includes/media.php
42 42 43 43 $post_id = intval($_REQUEST['post_id']); 44 44 45 if ( $post_id ) 46 $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 ) ) ); 45 if ( $post_id ) { 46 $args = array( 47 'fields' => 'count', 48 'post_type' => 'attachment', 49 'post_status' => 'any', 50 'post_parent' => $post_id, 51 'suppress_filters' => false, 52 'query_context' => 'gallery_attachment_count', 53 ); 47 54 55 $attachments = intval( get_posts( $args ) ); 56 } 57 48 58 if ( empty($attachments) ) { 49 59 unset($tabs['gallery']); 50 60 return $tabs; -
wp-includes/query.php
1369 1378 , 's' 1370 1379 , 'sentence' 1371 1380 , 'fields' 1381 , 'query_context' 1372 1382 ); 1373 1383 1374 1384 foreach ( $keys as $key ) { … … 2001 2013 case 'id=>parent': 2002 2014 $fields = "$wpdb->posts.ID, $wpdb->posts.post_parent"; 2003 2015 break; 2016 case 'count': 2017 $fields = "COUNT(*)"; 2018 break; 2004 2019 default: 2005 2020 $fields = "$wpdb->posts.*"; 2006 2021 } … … 2610 2625 2611 2626 return $r; 2612 2627 } 2628 2629 if ( 'count' == $q['fields'] ) { 2630 $this->posts = $wpdb->get_var($this->request); 2613 2631 2632 return $this->posts; 2633 } 2634 2614 2635 $this->posts = $wpdb->get_results($this->request); 2615 2636 2616 2637 // Raw results filter. Prior to status checks.