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. Built from https://develop.svn.wordpress.org/trunk@29890 git-svn-id: http://core.svn.wordpress.org/trunk@29646 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
parent
3ef60bf29b
commit
d64b1ed955
|
@ -1123,6 +1123,14 @@ class WP_Meta_Query {
|
|||
|
||||
$sql = $this->get_sql_clauses();
|
||||
|
||||
/*
|
||||
* If any JOINs are LEFT JOINs (as in the case of NOT EXISTS), then all JOINs should
|
||||
* be LEFT. Otherwise posts with no metadata will be excluded from results.
|
||||
*/
|
||||
if ( false !== strpos( $sql['join'], 'LEFT JOIN' ) ) {
|
||||
$sql['join'] = str_replace( 'INNER JOIN', 'LEFT JOIN', $sql['join'] );
|
||||
}
|
||||
|
||||
/**
|
||||
* Filter the meta query's generated SQL.
|
||||
*
|
||||
|
|
Loading…
Reference in New Issue