Make WordPress Core

Ticket #25538: 25538.unitspassed.diff

File 25538.unitspassed.diff, 1.6 KB (added by jackreichert, 11 years ago)

refactored patch, now passes unittesting

  • src/wp-includes/meta.php

    diff --git src/wp-includes/meta.php src/wp-includes/meta.php
    index dc19833..299bd41 100644
    class WP_Meta_Query { 
    770770                                $where["key-only-$key"] = $wpdb->prepare( "$meta_table.meta_key = %s", trim( $q['key'] ) );
    771771                }
    772772
     773        $where_meta_key = array();
    773774                foreach ( $queries as $k => $q ) {
    774775                        $meta_key = isset( $q['key'] ) ? trim( $q['key'] ) : '';
    775776                        $meta_type = $this->get_cast_for_type( isset( $q['type'] ) ? $q['type'] : '' );
    class WP_Meta_Query { 
    812813                        $join[$i] .= " ON ($primary_table.$primary_id_column = $alias.$meta_id_column)";
    813814
    814815                        $where[$k] = '';
    815                         if ( !empty( $meta_key ) )
    816                                 $where[$k] = $wpdb->prepare( "$alias.meta_key = %s", $meta_key );
     816                        if ( !empty( $meta_key ) ) {
     817                if( isset($q['compare']) ) {
     818                    $where_meta_key[$k] = $wpdb->prepare( "$alias.meta_key = %s", $meta_key );
     819                } else {
     820                    $where[$k] = $wpdb->prepare( "$alias.meta_key = %s", $meta_key );
     821                }
     822            }
    817823
    818824                        if ( is_null( $meta_value ) ) {
    819                                 if ( empty( $where[$k] ) )
     825                                if ( empty( $where[$k] ) && empty($where_meta_key) )
    820826                                        unset( $join[$i] );
    821827                                continue;
    822828                        }
    class WP_Meta_Query { 
    858864                else
    859865                        $where = ' AND (' . implode( "\n{$this->relation} ", $where ) . ' )';
    860866
     867        if ( !empty($where_meta_key) ) {
     868                        $where .= "\nAND " . implode( "\nAND ", $where_meta_key );
     869                }
     870
    861871                $join = implode( "\n", $join );
    862872                if ( ! empty( $join ) )
    863873                        $join = ' ' . $join;