Changeset 15766
- Timestamp:
- 10/09/2010 10:48:13 AM (14 years ago)
- Location:
- trunk/wp-includes
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/wp-includes/classes.php
r15765 r15766 545 545 class WP_Object_Query { 546 546 547 /** 548 * List of metadata queries 549 * 550 * A query is an associative array: 547 /* 548 * Populates the $meta_query property 549 * 550 * @access protected 551 * @since 3.1.0 552 * 553 * @param array $qv The query variables 554 */ 555 function parse_meta_query( &$qv ) { 556 $meta_query = array(); 557 558 // Simple query needs to be first for orderby=meta_value to work correctly 559 foreach ( array( 'key', 'value', 'compare', 'type' ) as $key ) { 560 if ( !empty( $qv[ "meta_$key" ] ) ) 561 $meta_query[0][ $key ] = $qv[ "meta_$key" ]; 562 } 563 564 if ( !empty( $qv['meta_query'] ) && is_array( $qv['meta_query'] ) ) { 565 $meta_query = array_merge( $meta_query, $qv['meta_query'] ); 566 } 567 568 $qv['meta_query'] = $meta_query; 569 } 570 571 /* 572 * Used internally to generate an SQL string for searching across multiple meta key = value pairs 573 * 574 * @access protected 575 * @since 3.1.0 576 * 577 * @param array $meta_query List of metadata queries. A single query is an associative array: 551 578 * - 'key' string The meta key 552 579 * - 'value' string|array The meta value … … 558 585 * Default: 'CHAR' 559 586 * 560 * @since 3.1.0561 * @access public562 * @var array563 */564 var $meta_query = array();565 566 /*567 * Populates the $meta_query property568 *569 * @access protected570 * @since 3.1.0571 *572 * @param array $qv The query variables573 */574 function parse_meta_query( $qv ) {575 if ( ! empty( $qv['meta_query'] ) && is_array( $qv['meta_query'] ) ) {576 $this->meta_query = $qv['meta_query'];577 }578 579 $meta_query = array();580 foreach ( array( 'key', 'value', 'compare', 'type' ) as $key ) {581 if ( ! empty( $qv[ "meta_$key" ] ) )582 $meta_query[ $key ] = $qv[ "meta_$key" ];583 }584 585 if ( ! empty( $meta_query ) ) {586 array_unshift( $this->meta_query, $meta_query );587 }588 }589 590 /*591 * Used internally to generate an SQL string for searching across multiple meta key = value pairs592 *593 * @access protected594 * @since 3.1.0595 *596 * @uses $this->meta_query597 *598 587 * @param string $primary_table 599 588 * @param string $primary_id_column … … 602 591 * @return array( $join_sql, $where_sql ) 603 592 */ 604 function get_meta_sql( $ primary_table, $primary_id_column, $meta_table, $meta_id_column ) {593 function get_meta_sql( $meta_query, $primary_table, $primary_id_column, $meta_table, $meta_id_column ) { 605 594 global $wpdb; 606 595 … … 610 599 $where = ''; 611 600 $i = 0; 612 foreach ( $ this->meta_query as $q ) {601 foreach ( $meta_query as $q ) { 613 602 $meta_key = isset( $q['key'] ) ? trim( $q['key'] ) : ''; 614 603 $meta_value = isset( $q['value'] ) ? $q['value'] : ''; -
trunk/wp-includes/query.php
r15765 r15766 1082 1082 unset($this->query); 1083 1083 $this->query_vars = array(); 1084 $this->meta_query = array();1085 1084 unset($this->queried_object); 1086 1085 unset($this->queried_object_id); … … 2115 2114 } 2116 2115 2117 list( $meta_join, $meta_where ) = $this->get_meta_sql( $ wpdb->posts, 'ID', $wpdb->postmeta, 'post_id' );2116 list( $meta_join, $meta_where ) = $this->get_meta_sql( $q['meta_query'], $wpdb->posts, 'ID', $wpdb->postmeta, 'post_id' ); 2118 2117 $join .= $meta_join; 2119 2118 $where .= $meta_where; -
trunk/wp-includes/user.php
r15723 r15766 459 459 } 460 460 461 $ this->meta_query[] = $cap_meta_query;462 } 463 464 list( $meta_join, $meta_where ) = $this->get_meta_sql( $ wpdb->users, 'ID', $wpdb->usermeta, 'user_id' );461 $qv['meta_query'][] = $cap_meta_query; 462 } 463 464 list( $meta_join, $meta_where ) = $this->get_meta_sql( $qv['meta_query'], $wpdb->users, 'ID', $wpdb->usermeta, 'user_id' ); 465 465 $this->query_from .= $meta_join; 466 466 $this->query_where .= $meta_where;
Note: See TracChangeset
for help on using the changeset viewer.