Changeset 36485 for trunk/src/wp-includes/taxonomy.php
- Timestamp:
- 02/06/2016 04:41:26 AM (9 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-includes/taxonomy.php
r36400 r36485 1061 1061 * Introduced the 'meta_query' and 'update_term_meta_cache' parameters. Converted to return 1062 1062 * a list of WP_Term objects. 1063 * @since 4.5.0 Introduced 'meta_key' and 'meta_value' parameters. Introduced the ability to order results by metadata. 1063 1064 * 1064 1065 * @global wpdb $wpdb WordPress database abstraction object. … … 1072 1073 * 'term_group', 'term_id', 'id', 'description'), 'count' for term 1073 1074 * taxonomy count, 'include' to match the 'order' of the $include param, 1074 * or 'none' to skip ORDER BY. Defaults to 'name'. 1075 * 'meta_value', 'meta_value_num', the value of `$meta_key`, the array 1076 * keys of `$meta_query`, or 'none' to omit the ORDER BY clause. 1077 * Defaults to 'name'. 1075 1078 * @type string $order Whether to order terms in ascending or descending order. 1076 1079 * Accepts 'ASC' (ascending) or 'DESC' (descending). … … 1120 1123 * @type array $meta_query Meta query clauses to limit retrieved terms by. 1121 1124 * See `WP_Meta_Query`. Default empty. 1125 * @type string $meta_key Limit terms to those matching a specific metadata key. Can be used in 1126 * conjunction with `$meta_value`. 1127 * @type string $meta_value Limit terms to those matching a specific metadata value. Usually used 1128 * in conjunction with `$meta_key`. 1122 1129 * } 1123 1130 * @return array|int|WP_Error List of WP_Term instances and their children. Will return WP_Error, if any of $taxonomies … … 1415 1422 $join = ''; 1416 1423 $distinct = ''; 1417 if ( ! empty( $args['meta_query'] ) ) { 1418 $mquery = new WP_Meta_Query( $args['meta_query'] ); 1419 $mq_sql = $mquery->get_sql( 'term', 't', 'term_id' ); 1420 1424 1425 $mquery = new WP_Meta_Query(); 1426 $mquery->parse_query_vars( $args ); 1427 $mq_sql = $mquery->get_sql( 'term', 't', 'term_id' ); 1428 $meta_clauses = $mquery->get_clauses(); 1429 1430 if ( ! empty( $meta_clauses ) ) { 1421 1431 $join .= $mq_sql['join']; 1422 1432 $where .= $mq_sql['where']; 1423 1433 $distinct .= "DISTINCT"; 1434 1435 // 'orderby' support. 1436 $allowed_keys = array(); 1437 $primary_meta_key = null; 1438 $primary_meta_query = reset( $meta_clauses ); 1439 if ( ! empty( $primary_meta_query['key'] ) ) { 1440 $primary_meta_key = $primary_meta_query['key']; 1441 $allowed_keys[] = $primary_meta_key; 1442 } 1443 $allowed_keys[] = 'meta_value'; 1444 $allowed_keys[] = 'meta_value_num'; 1445 $allowed_keys = array_merge( $allowed_keys, array_keys( $meta_clauses ) ); 1446 1447 if ( ! empty( $args['orderby'] ) && in_array( $args['orderby'], $allowed_keys ) ) { 1448 switch( $args['orderby'] ) { 1449 case $primary_meta_key: 1450 case 'meta_value': 1451 if ( ! empty( $primary_meta_query['type'] ) ) { 1452 $orderby = "ORDER BY CAST({$primary_meta_query['alias']}.meta_value AS {$primary_meta_query['cast']})"; 1453 } else { 1454 $orderby = "ORDER BY {$primary_meta_query['alias']}.meta_value"; 1455 } 1456 break; 1457 1458 case 'meta_value_num': 1459 $orderby = "ORDER BY {$primary_meta_query['alias']}.meta_value+0"; 1460 break; 1461 1462 default: 1463 if ( array_key_exists( $args['orderby'], $meta_clauses ) ) { 1464 // $orderby corresponds to a meta_query clause. 1465 $meta_clause = $meta_clauses[ $args['orderby'] ]; 1466 $orderby = "ORDER BY CAST({$meta_clause['alias']}.meta_value AS {$meta_clause['cast']})"; 1467 } 1468 break; 1469 } 1470 } 1424 1471 } 1425 1472
Note: See TracChangeset
for help on using the changeset viewer.