[wp-trac] [WordPress Trac] #22096: IN meta_query with empty array as meta_value results in invalid database query
WordPress Trac
noreply at wordpress.org
Thu Apr 11 06:07:28 UTC 2013
#22096: IN meta_query with empty array as meta_value results in invalid database
query
--------------------------+-----------------------------
Reporter: batmoo | Owner: wonderboymusic
Type: defect (bug) | Status: accepted
Priority: normal | Milestone: 3.6
Component: Query | Version: 3.1.3
Severity: normal | Resolution:
Keywords: has-patch |
--------------------------+-----------------------------
Comment (by batmoo):
Another example, this time when you combine a 'IN', 'NOT IN', 'BETWEEN',
'NOT BETWEEN' with an empty value and another valid IN:
{{{
new WP_Query( array(
'meta_query' => array(
'relation' => 'AND',
array( 'key' => 'key1', 'value' => array( 'value1',
'value1b' ), 'compare' => 'IN' ),
array( 'key' => 'key2', 'value' => array(), 'compare' =>
'NOT IN' )
)
) );
}}}
results in:
{{{
SELECT SQL_CALC_FOUND_ROWS wp_15797879_posts.ID FROM wp_15797879_posts
INNER JOIN wp_15797879_postmeta ON (wp_15797879_posts.ID =
wp_15797879_postmeta.post_id) WHERE 1=1 AND wp_15797879_posts.post_type =
\'post\' AND (wp_15797879_posts.post_status = \'publish\') AND (
(wp_15797879_postmeta.meta_key = 'key1' AND
CAST(wp_15797879_postmeta.meta_value AS CHAR) IN (\'value1\',\'value1b\'))
AND mt1.meta_key = 'key2' ) GROUP BY wp_15797879_posts.ID ORDER BY
wp_15797879_posts.post_date DESC LIMIT 0, 10
}}}
The {{{JOIN}}} for {{{mt1}}} is unset and the {{{meta_value}}} ignored
(http://core.trac.wordpress.org/browser/trunk/wp-
includes/meta.php?rev=23961#L789) resulting in an invalid query and an SQL
error:
{{{Unknown column 'mt1.meta_key' in 'where clause'}}}
--
Ticket URL: <http://core.trac.wordpress.org/ticket/22096#comment:6>
WordPress Trac <http://core.trac.wordpress.org/>
WordPress blogging software
More information about the wp-trac
mailing list