[wp-trac] [WordPress Trac] #18401: meta_query's value fails with arrays

WordPress Trac wp-trac at lists.automattic.com
Sun Aug 14 09:48:50 UTC 2011


#18401: meta_query's value fails with arrays
--------------------------+-----------------------------
 Reporter:  Doggie52      |      Owner:
     Type:  defect (bug)  |     Status:  new
 Priority:  normal        |  Milestone:  Awaiting Review
Component:  General       |    Version:  3.2.1
 Severity:  normal        |   Keywords:
--------------------------+-----------------------------
 Say I have a custom post type called 'review' and it has a custom field
 called 'score'. The one and only 'review' has a 'score' of 3. The
 following code will output a $posts object with that 'review'.

 {{{
 $args = array('post_type' => 'review');
 $args['meta_query'] = array(
         array(
         'key' => 'score',
         'value' => 3
 ));
 $posts = new WP_Query($args);
 }}}
 SQL request made:
 {{{
 SELECT SQL_CALC_FOUND_ROWS  wp_posts.* FROM wp_posts  INNER JOIN
 wp_postmeta ON (wp_posts.ID = wp_postmeta.post_id) WHERE 1=1  AND
 wp_posts.post_type = 'review' AND (wp_posts.post_status = 'publish' OR
 wp_posts.post_author = 1 AND wp_posts.post_status = 'private') AND (
 (wp_postmeta.meta_key = 'score' AND CAST(wp_postmeta.meta_value AS CHAR) =
 '3') ) GROUP BY wp_posts.ID ORDER BY wp_posts.post_date DESC LIMIT 0, 10
 }}}

 When passing an array with that '4', however, it does something out of the
 ordinary. The $posts object does not contain a post, and look at the SQL
 request around ''wp_postmeta.meta_value''.
 {{{
 $args = array('post_type' => 'review');
 $args['meta_query'] = array(
         array(
         'key' => 'score',
         'value' => array(3)
 ));
 }}}
 SQL request:
 {{{
 SELECT SQL_CALC_FOUND_ROWS  wp_posts.* FROM wp_posts  INNER JOIN
 wp_postmeta ON (wp_posts.ID = wp_postmeta.post_id) WHERE 1=1  AND
 wp_posts.post_type = 'review' AND (wp_posts.post_status = 'publish' OR
 wp_posts.post_author = 1 AND wp_posts.post_status = 'private') AND (
 (wp_postmeta.meta_key = 'score' AND CAST(wp_postmeta.meta_value AS CHAR) =
 '') ) GROUP BY wp_posts.ID ORDER BY wp_posts.post_date DESC LIMIT 0, 10
 }}}

 I apologize if the Component marked is incorrect, I was unable to find
 something that fit good enough.

-- 
Ticket URL: <http://core.trac.wordpress.org/ticket/18401>
WordPress Trac <http://core.trac.wordpress.org/>
WordPress blogging software


More information about the wp-trac mailing list