WordPress.org

Make WordPress Core

Ticket #23268: 23268.diff

File 23268.diff, 577 bytes (added by chrisguitarguy, 5 years ago)

Make WP_Meta_Query respect NOT EXISTS queries without values

  • wp-includes/meta.php

    diff --git wp-includes/meta.php wp-includes/meta.php
    index 8a9dad9..d3e4f82 100644
    class WP_Meta_Query { 
    708708                // Split out the meta_key only queries (we can only do this for OR) 
    709709                if ( 'OR' == $this->relation ) { 
    710710                        foreach ( $this->queries as $k => $q ) { 
    711                                 if ( ! isset( $q['value'] ) && ! empty( $q['key'] ) ) 
     711                                if ( ( empty( $q['compare'] ) || 'NOT EXISTS' != $q['compare'] ) && ! isset( $q['value'] ) && ! empty( $q['key'] ) ) 
    712712                                        $key_only_queries[$k] = $q; 
    713713                                else 
    714714                                        $queries[$k] = $q;