further meta query optimization. props aaroncampbell. fixes #9124

git-svn-id: http://svn.automattic.com/wordpress/trunk@15730 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
scribu 2010-10-05 23:06:20 +00:00
parent 7630099b45
commit ef709f8953
1 changed files with 8 additions and 10 deletions

View File

@ -552,17 +552,17 @@ class WP_Object_Query {
* @param array $qv The query variables * @param array $qv The query variables
*/ */
function parse_meta_query( $qv ) { function parse_meta_query( $qv ) {
if ( !empty( $qv['meta_query'] ) && is_array( $qv['meta_query'] ) ) { if ( ! empty( $qv['meta_query'] ) && is_array( $qv['meta_query'] ) ) {
$this->meta_query = $qv['meta_query']; $this->meta_query = $qv['meta_query'];
} }
$meta_query = array(); $meta_query = array();
foreach ( array( 'key', 'value', 'compare' ) as $key ) { foreach ( array( 'key', 'value', 'compare', 'type' ) as $key ) {
if ( !empty( $qv[ "meta_$key" ] ) ) if ( ! empty( $qv[ "meta_$key" ] ) )
$meta_query[ $key ] = $qv[ "meta_$key" ]; $meta_query[ $key ] = $qv[ "meta_$key" ];
} }
if ( !empty( $meta_query ) ) { if ( ! empty( $meta_query ) ) {
array_unshift( $this->meta_query, $meta_query ); array_unshift( $this->meta_query, $meta_query );
} }
} }
@ -593,14 +593,12 @@ class WP_Object_Query {
$meta_compare = isset( $q['compare'] ) ? strtoupper( $q['compare'] ) : '='; $meta_compare = isset( $q['compare'] ) ? strtoupper( $q['compare'] ) : '=';
$meta_type = isset( $q['type'] ) ? strtoupper( $q['type'] ) : 'CHAR'; $meta_type = isset( $q['type'] ) ? strtoupper( $q['type'] ) : 'CHAR';
if ( !in_array( $meta_compare, array( '=', '!=', '>', '>=', '<', '<=', 'LIKE', 'IN', 'BETWEEN' ) ) ) if ( ! in_array( $meta_compare, array( '=', '!=', '>', '>=', '<', '<=', 'LIKE', 'IN', 'BETWEEN' ) ) )
$meta_compare = '='; $meta_compare = '=';
if ( 'STRING' == $meta_type ) if ( 'NUMERIC' == $meta_type )
$meta_type = 'CHAR';
elseif ( 'NUMERIC' == $meta_type )
$meta_type = 'SIGNED'; $meta_type = 'SIGNED';
elseif ( !in_array( $meta_type, array( 'BINARY', 'CHAR', 'DATE', 'DATETIME', 'DECIMAL', 'SIGNED', 'TIME', 'UNSIGNED' ) ) ) elseif ( ! in_array( $meta_type, array( 'BINARY', 'CHAR', 'DATE', 'DATETIME', 'DECIMAL', 'SIGNED', 'TIME', 'UNSIGNED' ) ) )
$meta_type = 'CHAR'; $meta_type = 'CHAR';
if ( empty( $meta_key ) && empty( $meta_value ) ) if ( empty( $meta_key ) && empty( $meta_value ) )
@ -618,7 +616,7 @@ class WP_Object_Query {
$where .= $wpdb->prepare( " AND $alias.meta_key = %s", $meta_key ); $where .= $wpdb->prepare( " AND $alias.meta_key = %s", $meta_key );
if ( in_array( $meta_compare, array( 'IN', 'BETWEEN' ) ) ) { if ( in_array( $meta_compare, array( 'IN', 'BETWEEN' ) ) ) {
if ( !is_array( $meta_value ) ) if ( ! is_array( $meta_value ) )
$meta_value = preg_split( '/[,\s]+/', $meta_value ); $meta_value = preg_split( '/[,\s]+/', $meta_value );
} else { } else {
$meta_value = trim( $meta_value ); $meta_value = trim( $meta_value );