[wp-trac] [WordPress Trac] #23268: NOT EXISTS meta query with OR releation
WordPress Trac
noreply at wordpress.org
Tue Jan 22 21:14:14 UTC 2013
#23268: NOT EXISTS meta query with OR releation
-----------------------------+--------------------------
Reporter: timfield | Type: defect (bug)
Status: new | Priority: normal
Milestone: Awaiting Review | Component: Query
Version: | Severity: normal
Keywords: |
-----------------------------+--------------------------
With this meta query ( which is trying to exclude posts that have the
app_exclude checkbox checked, without excluding posts that don't have it
set at all )
{{{
$query['meta_query'] = array(
'relation' => 'OR',
array(
'key' => 'app_exclude',
'compare' => 'NOT EXISTS'
),
array(
'key' => 'app_exclude',
'compare' => '!=',
'value' => '1'
),
);
}}}
I'd expect / hope to get this sql.
{{{
SELECT SQL_CALC_FOUND_ROWS
wp_posts.ID
FROM
wp_posts
LEFT JOIN
wp_postmeta ON (wp_posts.ID = wp_postmeta.post_id AND
wp_postmeta.meta_key = 'app_exclude')
INNER JOIN
wp_postmeta AS mt1 ON (wp_posts.ID = mt1.post_id)
WHERE
1 = 1 AND wp_posts.post_type = 'post' AND (wp_posts.post_status =
'publish') AND (wp_postmeta.post_id IS NULL
OR (mt1.meta_key = 'app_exclude' AND CAST(mt1.meta_value AS CHAR) !=
'1'))
GROUP BY wp_posts.ID
ORDER BY wp_posts.post_date DESC
LIMIT 0 , 6
}}}
but I get this SQL
{{{
SELECT SQL_CALC_FOUND_ROWS
wp_posts.ID
FROM
wp_posts
LEFT JOIN
wp_postmeta ON (wp_posts.ID = wp_postmeta.post_id AND
wp_postmeta.meta_key = 'app_exclude')
INNER JOIN
wp_postmeta AS mt1 ON (wp_posts.ID = mt1.post_id)
WHERE
1 = 1 AND wp_posts.post_type = 'post' AND (wp_posts.post_status =
'publish')
AND (wp_postmeta.post_id IS NULL AND (mt1.meta_key = 'app_exclude' AND
CAST(mt1.meta_value AS CHAR) != '1'))
GROUP BY wp_posts.ID
ORDER BY wp_posts.post_date DESC
LIMIT 0 , 6
}}}
Note the... (wp_postmeta.post_id IS NULL '''AND''' (mt1.meta_key =
'app_exclude' AND CAST(mt1.meta_value AS CHAR) != '1'))
--
Ticket URL: <http://core.trac.wordpress.org/ticket/23268>
WordPress Trac <http://core.trac.wordpress.org/>
WordPress blogging software
More information about the wp-trac
mailing list