Make WordPress Core

Changeset 18825


Ignore:
Timestamp:
09/29/2011 10:10:56 PM (12 years ago)
Author:
duck_
Message:

Automatically set 'compare' => 'IN' in WP_Meta_Query::get_sql() when the meta value is an array. Props ldebrouwer, SergeyBiryukov. Fixes #16829.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/wp-includes/meta.php

    r18816 r18825  
    710710        foreach ( $this->queries as $k => $q ) {
    711711            $meta_key = isset( $q['key'] ) ? trim( $q['key'] ) : '';
    712             $meta_compare = isset( $q['compare'] ) ? strtoupper( $q['compare'] ) : '=';
    713712            $meta_type = isset( $q['type'] ) ? strtoupper( $q['type'] ) : 'CHAR';
    714 
    715             if ( ! in_array( $meta_compare, array( '=', '!=', '>', '>=', '<', '<=', 'LIKE', 'NOT LIKE', 'IN', 'NOT IN', 'BETWEEN', 'NOT BETWEEN' ) ) )
    716                 $meta_compare = '=';
    717713
    718714            if ( 'NUMERIC' == $meta_type )
     
    740736
    741737            $meta_value = $q['value'];
     738
     739            $meta_compare = is_array( $meta_value ) ? 'IN' : '=';
     740            if ( isset( $q['compare'] ) )
     741                $meta_compare = strtoupper( $q['compare'] );
     742
     743            if ( ! in_array( $meta_compare, array( '=', '!=', '>', '>=', '<', '<=', 'LIKE', 'NOT LIKE', 'IN', 'NOT IN', 'BETWEEN', 'NOT BETWEEN' ) ) )
     744                $meta_compare = '=';
    742745
    743746            if ( in_array( $meta_compare, array( 'IN', 'NOT IN', 'BETWEEN', 'NOT BETWEEN' ) ) ) {
Note: See TracChangeset for help on using the changeset viewer.