Make WordPress Core

Ticket #22967: 22967.2.patch

File 22967.2.patch, 1.6 KB (added by gradyetc, 12 years ago)
  • src/wp-includes/meta.php

     
    753753                // Split out the meta_key only queries (we can only do this for OR)
    754754                if ( 'OR' == $this->relation ) {
    755755                        foreach ( $this->queries as $k => $q ) {
    756                                 if ( ! isset( $q['value'] ) && ! empty( $q['key'] ) )
     756                                if ( ! array_key_exists( 'value', $q ) && ! empty( $q['key'] ) )
    757757                                        $key_only_queries[$k] = $q;
    758758                                else
    759759                                        $queries[$k] = $q;
     
    774774                        $meta_key = isset( $q['key'] ) ? trim( $q['key'] ) : '';
    775775                        $meta_type = $this->get_cast_for_type( isset( $q['type'] ) ? $q['type'] : '' );
    776776
     777                        if ( array_key_exists( 'value', $q ) && is_null( $q['value'] ) )
     778                                $q['value'] = '';
     779
    777780                        $meta_value = isset( $q['value'] ) ? $q['value'] : null;
    778781
    779782                        if ( isset( $q['compare'] ) )
  • tests/phpunit/tests/meta/query.php

     
    105105                $this->assertEquals( 1, substr_count( $sql['where'], "$wpdb->postmeta.meta_key = 'my_third_key'" ) );
    106106
    107107        }
     108
     109        /**
     110         * @ticket 22967
     111         */
     112        function test_null_value_sql() {
     113                global $wpdb;
     114
     115                $query = new WP_Meta_Query( array(
     116                        array( 'key' => 'abc', 'value' => null, 'compare' => '=' )
     117                ) );
     118                $sql = $query->get_sql( 'post', $wpdb->posts, 'ID', $this );
     119
     120                $this->assertEquals( 1, substr_count( $sql['where'], "CAST($wpdb->postmeta.meta_value AS CHAR) = '')" ) );
     121        }
    108122}