Ticket #10746: wp_count_terms.diff
| File wp_count_terms.diff, 3.3 KB (added by , 16 years ago) |
|---|
-
wp-includes/taxonomy.php
642 642 $args['hierarchical'] = false; 643 643 $args['pad_counts'] = false; 644 644 } 645 645 646 extract($args, EXTR_SKIP); 646 647 647 648 if ( $child_of ) { … … 769 770 } 770 771 771 772 $selects = array(); 772 if ( 'all' == $fields ) 773 $selects = array('t.*', 'tt.*'); 774 else if ( 'ids' == $fields ) 775 $selects = array('t.term_id', 'tt.parent', 'tt.count'); 776 else if ( 'names' == $fields ) 777 $selects = array('t.term_id', 'tt.parent', 'tt.count', 't.name'); 778 $select_this = implode(', ', apply_filters( 'get_terms_fields', $selects, $args )); 773 switch ( $fields ) { 774 case 'all': 775 $selects = array('t.*', 'tt.*'); 776 break; 777 case 'ids': 778 $selects = array('t.term_id', 'tt.parent', 'tt.count'); 779 break; 780 case 'names': 781 $selects = array('t.term_id', 'tt.parent', 'tt.count', 't.name'); 782 break; 783 case 'count': 784 $selects = array('COUNT(*)'); 785 } 786 $select_this = implode(', ', apply_filters( 'get_terms_fields', $selects, $args )); 779 787 780 788 $query = "SELECT $select_this FROM $wpdb->terms AS t INNER JOIN $wpdb->term_taxonomy AS tt ON t.term_id = tt.term_id WHERE tt.taxonomy IN ($in_taxonomies) $where ORDER BY $orderby $order $limit"; 781 789 790 if ( 'count' == $fields ) 791 return $wpdb->get_var($query); 792 782 793 $terms = $wpdb->get_results($query); 783 794 if ( 'all' == $fields ) { 784 795 update_term_cache($terms); … … 1024 1035 /** 1025 1036 * Count how many terms are in Taxonomy. 1026 1037 * 1027 * Default $args is 'ignore_empty' which can be <code>'ignore_empty=true'</code> 1028 * or <code>array('ignore_empty' => true);</code>. 1038 * Default $args is 'hide_empty' which can be 'hide_empty=true' or array('hide_empty' => true). 1029 1039 * 1030 1040 * @package WordPress 1031 1041 * @subpackage Taxonomy 1032 1042 * @since 2.3.0 1033 1043 * 1034 * @uses $wpdb1044 * @uses get_terms() 1035 1045 * @uses wp_parse_args() Turns strings into arrays and merges defaults into an array. 1036 1046 * 1037 1047 * @param string $taxonomy Taxonomy name 1038 * @param array|string $args Overwrite defaults 1048 * @param array|string $args Overwrite defaults. See get_terms() 1039 1049 * @return int How many terms are in $taxonomy 1040 1050 */ 1041 1051 function wp_count_terms( $taxonomy, $args = array() ) { 1042 global $wpdb; 1043 1044 $defaults = array('ignore_empty' => false); 1052 $defaults = array('hide_empty' => false); 1045 1053 $args = wp_parse_args($args, $defaults); 1046 extract($args, EXTR_SKIP);1047 1054 1048 $where = ''; 1049 if ( $ignore_empty ) 1050 $where = 'AND count > 0'; 1055 // backwards compatibility 1056 if ( isset($args['ignore_empty']) ) { 1057 $args['hide_empty'] = $args['ignore_empty']; 1058 unset($args['ignore_empty']); 1059 } 1051 1060 1052 return $wpdb->get_var( $wpdb->prepare("SELECT COUNT(*) FROM $wpdb->term_taxonomy WHERE taxonomy = %s $where", $taxonomy) ); 1061 $args['fields'] = 'count'; 1062 1063 return get_terms($taxonomy, $args); 1053 1064 } 1054 1065 1055 1066 /** -
wp-admin/edit-tags.php
190 190 'format' => '', 191 191 'prev_text' => __('«'), 192 192 'next_text' => __('»'), 193 'total' => ceil(wp_count_terms($taxonomy ) / $tags_per_page),193 'total' => ceil(wp_count_terms($taxonomy, array('search' => $_GET['s'])) / $tags_per_page), 194 194 'current' => $pagenum 195 195 )); 196 196