Ticket #10746: wp_count_terms.2.diff
| File wp_count_terms.2.diff, 3.8 KB (added by , 16 years ago) |
|---|
-
wp-includes/taxonomy.php
748 748 $args['hierarchical'] = false; 749 749 $args['pad_counts'] = false; 750 750 } 751 751 752 extract($args, EXTR_SKIP); 752 753 753 754 if ( $child_of ) { … … 871 872 } 872 873 873 874 $selects = array(); 874 if ( 'all' == $fields ) 875 $selects = array('t.*', 'tt.*'); 876 else if ( 'ids' == $fields || 'id=>parent' == $fields ) 877 $selects = array('t.term_id', 'tt.parent', 'tt.count'); 878 else if ( 'names' == $fields ) 879 $selects = array('t.term_id', 'tt.parent', 'tt.count', 't.name'); 875 switch ( $fields ) { 876 case 'all': 877 $selects = array('t.*', 'tt.*'); 878 break; 879 case 'ids': 880 case 'id=>parent': 881 $selects = array('t.term_id', 'tt.parent', 'tt.count'); 882 break; 883 case 'names': 884 $selects = array('t.term_id', 'tt.parent', 'tt.count', 't.name'); 885 break; 886 case 'count': 887 $selects = array('COUNT(*)'); 888 } 880 889 $select_this = implode(', ', apply_filters( 'get_terms_fields', $selects, $args )); 881 890 882 891 $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"; 883 892 893 if ( 'count' == $fields ) { 894 $term_count = $wpdb->get_var($query); 895 return $term_count; 896 } 897 884 898 $terms = $wpdb->get_results($query); 885 899 if ( 'all' == $fields ) { 886 900 update_term_cache($terms); … … 1130 1144 /** 1131 1145 * Count how many terms are in Taxonomy. 1132 1146 * 1133 * Default $args is 'ignore_empty' which can be <code>'ignore_empty=true'</code> 1134 * or <code>array('ignore_empty' => true);</code>. 1147 * Default $args is 'hide_empty' which can be 'hide_empty=true' or array('hide_empty' => true). 1135 1148 * 1136 1149 * @package WordPress 1137 1150 * @subpackage Taxonomy 1138 1151 * @since 2.3.0 1139 1152 * 1140 * @uses $wpdb1153 * @uses get_terms() 1141 1154 * @uses wp_parse_args() Turns strings into arrays and merges defaults into an array. 1142 1155 * 1143 1156 * @param string $taxonomy Taxonomy name 1144 * @param array|string $args Overwrite defaults 1157 * @param array|string $args Overwrite defaults. See get_terms() 1145 1158 * @return int How many terms are in $taxonomy 1146 1159 */ 1147 1160 function wp_count_terms( $taxonomy, $args = array() ) { 1148 global $wpdb; 1149 1150 $defaults = array('ignore_empty' => false); 1161 $defaults = array('hide_empty' => false); 1151 1162 $args = wp_parse_args($args, $defaults); 1152 extract($args, EXTR_SKIP);1153 1163 1154 $where = ''; 1155 if ( $ignore_empty ) 1156 $where = 'AND count > 0'; 1164 // backwards compatibility 1165 if ( isset($args['ignore_empty']) ) { 1166 $args['hide_empty'] = $args['ignore_empty']; 1167 unset($args['ignore_empty']); 1168 } 1157 1169 1158 return $wpdb->get_var( $wpdb->prepare("SELECT COUNT(*) FROM $wpdb->term_taxonomy WHERE taxonomy = %s $where", $taxonomy) ); 1170 $args['fields'] = 'count'; 1171 1172 return get_terms($taxonomy, $args); 1159 1173 } 1160 1174 1161 1175 /** -
wp-admin/edit-tags.php
230 230 $tags_per_page = apply_filters( 'edit_' . $taxonomy . '_per_page', $tags_per_page ); 231 231 } 232 232 233 if ( !empty($_GET['s']) ) {233 if ( !empty($_GET['s']) ) 234 234 $searchterms = trim(stripslashes($_GET['s'])); 235 $total_terms = count( get_terms( $taxonomy, array( 'search' => $searchterms, 'number' => 0, 'hide_empty' => 0 ) ) ); 236 } else { 235 else 237 236 $searchterms = ''; 238 $total_terms = wp_count_terms($taxonomy);239 }240 237 241 238 $page_links = paginate_links( array( 242 239 'base' => add_query_arg( 'pagenum', '%#%' ), 243 240 'format' => '', 244 241 'prev_text' => __('«'), 245 242 'next_text' => __('»'), 246 'total' => ceil( $total_terms/ $tags_per_page),243 'total' => ceil(wp_count_terms($taxonomy, array('search' => $searchterms)) / $tags_per_page), 247 244 'current' => $pagenum 248 245 )); 249 246 … … 409 406 410 407 include('admin-footer.php'); 411 408 412 ?> 413 No newline at end of file 409 ?>