Make WordPress Core


Ignore:
Timestamp:
10/14/2014 02:16:28 AM (12 years ago)
Author:
boonebgorges
Message:

Use only LEFT JOINs when a meta_query contains a NOT EXISTS clause.

Mixing LEFT and INNER JOIN in these cases results in posts with no metadata
being improperly excluded from results.

Props johnrom.
Fixes #29062.

File:
1 edited

Legend:

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

    r29887 r29890  
    11231123
    11241124        $sql = $this->get_sql_clauses();
     1125
     1126        /*
     1127         * If any JOINs are LEFT JOINs (as in the case of NOT EXISTS), then all JOINs should
     1128         * be LEFT. Otherwise posts with no metadata will be excluded from results.
     1129         */
     1130        if ( false !== strpos( $sql['join'], 'LEFT JOIN' ) ) {
     1131            $sql['join'] = str_replace( 'INNER JOIN', 'LEFT JOIN', $sql['join'] );
     1132        }
    11251133
    11261134        /**
Note: See TracChangeset for help on using the changeset viewer.