Changeset 31340 for trunk/src/wp-includes/meta.php
- Timestamp:
- 02/05/2015 07:37:47 PM (10 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-includes/meta.php
r31312 r31340 946 946 * 947 947 * @since 3.2.0 948 * @since 4.2.0 Introduced the `$name` parameter, for improved `$orderby` support in the parent query.948 * @since 4.2.0 Introduced support for naming query clauses by associative array keys. 949 949 * 950 950 * @access public 951 951 * 952 952 * @param array $meta_query { 953 * Array of meta query clauses. 953 * Array of meta query clauses. When first-order clauses use strings as their array keys, they may be 954 * referenced in the 'orderby' parameter of the parent query. 954 955 * 955 956 * @type string $relation Optional. The MySQL keyword used to join … … 968 969 * 'DATETIME', 'DECIMAL', 'SIGNED', 'TIME', or 'UNSIGNED'. 969 970 * Default is 'CHAR'. 970 * @type string $name Optional. A unique identifier for the clause. If provided, `$name` can be971 * referenced in the `$orderby` parameter of the parent query.972 971 * } 973 972 * } … … 1017 1016 } 1018 1017 1019 $clean_queries[ ] = $query;1018 $clean_queries[ $key ] = $query; 1020 1019 1021 1020 // Otherwise, it's a nested query, so we recurse. … … 1024 1023 1025 1024 if ( ! empty( $cleaned_query ) ) { 1026 $clean_queries[ ] = $cleaned_query;1025 $clean_queries[ $key ] = $cleaned_query; 1027 1026 } 1028 1027 } … … 1271 1270 // This is a first-order clause. 1272 1271 if ( $this->is_first_order_clause( $clause ) ) { 1273 $clause_sql = $this->get_sql_for_clause( $clause, $query );1272 $clause_sql = $this->get_sql_for_clause( $clause, $query, $key ); 1274 1273 1275 1274 $where_count = count( $clause_sql['where'] ); … … 1322 1321 * @access public 1323 1322 * 1324 * @param array $clause Query clause, passed by reference. 1325 * @param array $parent_query Parent query array. 1323 * @param array $clause Query clause, passed by reference. 1324 * @param array $parent_query Parent query array. 1325 * @param string $clause_key Optional. The array key used to name the clause in the original `$meta_query` 1326 * parameters. If not provided, a key will be generated automatically. 1326 1327 * @return array { 1327 1328 * Array containing JOIN and WHERE SQL clauses to append to a first-order query. … … 1331 1332 * } 1332 1333 */ 1333 public function get_sql_for_clause( &$clause, $parent_query ) {1334 public function get_sql_for_clause( &$clause, $parent_query, $clause_key = '' ) { 1334 1335 global $wpdb; 1335 1336 … … 1392 1393 $clause['cast'] = $meta_type; 1393 1394 1395 // Fallback for clause keys is the table alias. 1396 if ( ! $clause_key ) { 1397 $clause_key = $clause['alias']; 1398 } 1399 1400 // Ensure unique clause keys, so none are overwritten. 1401 $iterator = 1; 1402 $clause_key_base = $clause_key; 1403 while ( isset( $this->clauses[ $clause_key ] ) ) { 1404 $clause_key = $clause_key_base . '-' . $iterator; 1405 $iterator++; 1406 } 1407 1394 1408 // Store the clause in our flat array. 1395 $clause_name = isset( $clause['name'] ) ? $clause['name'] : $clause['alias']; 1396 $this->clauses[ $clause_name ] =& $clause; 1409 $this->clauses[ $clause_key ] =& $clause; 1397 1410 1398 1411 // Next, build the WHERE clause. … … 1472 1485 1473 1486 /** 1474 * Get a flattened list of sanitized meta clauses , indexed by clause 'name'.1487 * Get a flattened list of sanitized meta clauses. 1475 1488 * 1476 1489 * This array should be used for clause lookup, as when the table alias and CAST type must be determined for
Note: See TracChangeset
for help on using the changeset viewer.