Ticket #17011: 17011.2.diff
File 17011.2.diff, 2.2 KB (added by , 14 years ago) |
---|
-
wp-includes/query.php
2478 2478 $clauses = call_user_func_array( '_get_meta_sql', array( $q['meta_query'], 'post', $wpdb->posts, 'ID', &$this) ); 2479 2479 $join .= $clauses['join']; 2480 2480 $where .= $clauses['where']; 2481 $distinct = 'DISTINCT'; 2481 2482 } 2482 2483 2483 2484 // Apply filters on where and join prior to paging so that any -
wp-includes/meta.php
382 382 383 383 $meta_id_column = esc_sql( $type . '_id' ); 384 384 385 $relation = 'AND'; 386 if( isset( $meta_query['relation'] ) && strtoupper( $meta_query['relation'] ) == 'OR' ) { 387 $relation = 'OR'; 388 } else { 389 $meta_query['relation'] = ''; 390 } 391 unset( $meta_query['relation'] ); 392 385 393 $join = ''; 386 $where = '';394 $where = array(); 387 395 $i = 0; 388 foreach ( $meta_query as $ q ) {396 foreach ( $meta_query as $k => $q ) { 389 397 $meta_key = isset( $q['key'] ) ? trim( $q['key'] ) : ''; 390 398 $meta_value = isset( $q['value'] ) ? $q['value'] : ''; 391 399 $meta_compare = isset( $q['compare'] ) ? strtoupper( $q['compare'] ) : '='; … … 411 419 $i++; 412 420 413 421 if ( !empty( $meta_key ) ) 414 $where .= $wpdb->prepare( " AND$alias.meta_key = %s", $meta_key );422 $where[$k] = $wpdb->prepare( "$alias.meta_key = %s", $meta_key ); 415 423 416 424 if ( in_array( $meta_compare, array( 'IN', 'NOT IN', 'BETWEEN', 'NOT BETWEEN' ) ) ) { 417 425 if ( ! is_array( $meta_value ) ) … … 439 447 if ( '_wp_zero_value' == $meta_value ) 440 448 $meta_value = 0; 441 449 442 $where .= $wpdb->prepare( " AND CAST($alias.meta_value AS {$meta_type}) {$meta_compare} {$meta_compare_string}", $meta_value );450 $where[$k] = '(' . $where[$k] . $wpdb->prepare( " AND CAST($alias.meta_value AS {$meta_type}) {$meta_compare} {$meta_compare_string})", $meta_value ); 443 451 } 452 453 $where = ' AND ( '. implode( " $relation ", $where ) .' )'; 444 454 445 455 return apply_filters_ref_array( 'get_meta_sql', array( compact( 'join', 'where' ), $meta_query, $type, $primary_table, $primary_id_column, &$context ) ); 446 456 }