Changeset 36614 for trunk/src/wp-includes/taxonomy.php
- Timestamp:
- 02/22/2016 10:16:37 PM (9 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-includes/taxonomy.php
r36598 r36614 1073 1073 * along with the $args array. 1074 1074 * 1075 * Prior to 4.5.0, the first parameter of `get_terms()` was a taxonomy or list of taxonomies: 1076 * 1077 * $terms = get_terms( 'post_tag', array( 1078 * 'hide_empty' => false, 1079 * ) ); 1080 * 1081 * Since 4.5.0, taxonomies should be passed via the 'taxonomy' argument in the `$args` array: 1082 * 1083 * $terms = get_terms( array( 1084 * 'taxonomy' => 'post_tag', 1085 * 'hide_empty' => false, 1086 * ) ); 1087 * 1075 1088 * @since 2.3.0 1076 1089 * @since 4.2.0 Introduced 'name' and 'childless' parameters. … … 1078 1091 * Introduced the 'meta_query' and 'update_term_meta_cache' parameters. Converted to return 1079 1092 * a list of WP_Term objects. 1080 * @since 4.5.0 Introduced 'meta_key' and 'meta_value' parameters. Introduced the ability to order results by metadata. 1093 * @since 4.5.0 Changed the function signature so that the `$args` array can be provided as the first parameter. 1094 * Introduced 'meta_key' and 'meta_value' parameters. Introduced the ability to order results by metadata. 1095 * 1096 * @internal The `$deprecated` parameter is parsed for backward compatibility only. 1081 1097 * 1082 1098 * @global wpdb $wpdb WordPress database abstraction object. 1083 1099 * @global array $wp_filter 1084 1100 * 1085 * @param string|array $taxonomies Taxonomy name or list of Taxonomy names.1086 1101 * @param array|string $args { 1087 1102 * Optional. Array or string of arguments to get terms. 1088 1103 * 1104 * @type string|array $taxonomy Taxonomy name, or array of taxonomies, to which results should 1105 * be limited. 1089 1106 * @type string $orderby Field(s) to order terms by. Accepts term fields ('name', 'slug', 1090 1107 * 'term_group', 'term_id', 'id', 'description'), 'count' for term … … 1145 1162 * in conjunction with `$meta_key`. 1146 1163 * } 1164 * @param array $deprecated Argument array, when using the legacy function parameter format. If present, this 1165 * parameter will be interpreted as `$args`, and the first function parameter will 1166 * be parsed as a taxonomy or array of taxonomies. 1147 1167 * @return array|int|WP_Error List of WP_Term instances and their children. Will return WP_Error, if any of $taxonomies 1148 1168 * do not exist. 1149 1169 */ 1150 function get_terms( $ taxonomies, $args= '' ) {1170 function get_terms( $args = array(), $deprecated = '' ) { 1151 1171 global $wpdb; 1152 $empty_array = array();1153 1154 if ( ! is_array( $taxonomies ) ) {1155 $taxonomies = array( $taxonomies );1156 }1157 1158 foreach ( $taxonomies as $taxonomy ) {1159 if ( ! taxonomy_exists($taxonomy) ) {1160 return new WP_Error( 'invalid_taxonomy', __( 'Invalid taxonomy' ) );1161 }1162 }1163 1172 1164 1173 $defaults = array( 1174 'taxonomy' => null, 1165 1175 'orderby' => 'name', 1166 1176 'order' => 'ASC', … … 1188 1198 ); 1189 1199 1200 /* 1201 * Legacy argument format ($taxonomy, $args) takes precedence. 1202 * 1203 * We detect legacy argument format by checking if 1204 * (a) a second non-empty parameter is passed, or 1205 * (b) the first parameter shares no keys with the default array (ie, it's a list of taxonomies) 1206 */ 1207 $key_intersect = array_intersect_key( $defaults, (array) $args ); 1208 $do_legacy_args = $deprecated || empty( $key_intersect ); 1209 1210 $taxonomies = null; 1211 if ( $do_legacy_args ) { 1212 $taxonomies = (array) $args; 1213 $args = $deprecated; 1214 } elseif ( isset( $args['taxonomy'] ) && null !== $args['taxonomy'] ) { 1215 $taxonomies = (array) $args['taxonomy']; 1216 unset( $args['taxonomy'] ); 1217 } 1218 1219 $empty_array = array(); 1220 1221 if ( $taxonomies ) { 1222 foreach ( $taxonomies as $taxonomy ) { 1223 if ( ! taxonomy_exists($taxonomy) ) { 1224 return new WP_Error( 'invalid_taxonomy', __( 'Invalid taxonomy' ) ); 1225 } 1226 } 1227 } 1228 1190 1229 /** 1191 1230 * Filter the terms query default arguments. … … 1205 1244 // Save queries by not crawling the tree in the case of multiple taxes or a flat tax. 1206 1245 $has_hierarchical_tax = false; 1207 foreach ( $taxonomies as $_tax ) { 1208 if ( is_taxonomy_hierarchical( $_tax ) ) { 1209 $has_hierarchical_tax = true; 1246 if ( $taxonomies ) { 1247 foreach ( $taxonomies as $_tax ) { 1248 if ( is_taxonomy_hierarchical( $_tax ) ) { 1249 $has_hierarchical_tax = true; 1250 } 1210 1251 } 1211 1252 } … … 1312 1353 $where_conditions = array(); 1313 1354 1314 $where_conditions[] = "tt.taxonomy IN ('" . implode("', '", $taxonomies) . "')"; 1355 if ( $taxonomies ) { 1356 $where_conditions[] = "tt.taxonomy IN ('" . implode("', '", $taxonomies) . "')"; 1357 } 1315 1358 1316 1359 $exclude = $args['exclude'];
Note: See TracChangeset
for help on using the changeset viewer.