[wp-trac] [WordPress Trac] #17165: Introduce WP_Meta_Query

WordPress Trac wp-trac at lists.automattic.com
Sat Apr 23 19:26:56 UTC 2011


#17165: Introduce WP_Meta_Query
------------------------------+------------------
 Reporter:  scribu            |       Owner:
     Type:  enhancement       |      Status:  new
 Priority:  normal            |   Milestone:  3.2
Component:  Query             |     Version:
 Severity:  normal            |  Resolution:
 Keywords:  has-patch commit  |
------------------------------+------------------

Comment (by greuben):

 One small change, check if parsed queries are arrays.
 Try this query
 {{{
 $q = new WP_Query(
 array(
         'fields' => 'ids',
         'ignore_sticky_posts' => true,
         'meta_query' => array(
                 'test' => 'test',
                 array(
                         'key' => 'foo',
                         'value' => array( 'foobar' ),
                         'compare' => 'IN'
                 )
         )
 ) );
 echo  $q->request;
 }}}

 The result
 {{{
 SELECT SQL_CALC_FOUND_ROWS wp_posts.ID FROM wp_posts INNER JOIN
 wp_postmeta ON (wp_posts.ID = wp_postmeta.post_id) 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' OR wp_posts.post_status =
 'private') AND wp_postmeta.meta_key = 't' AND CAST(wp_postmeta.meta_value
 AS CHAR) = 't' AND mt1.meta_key = 'foo' AND CAST(mt1.meta_value AS CHAR)
 IN ('foobar') GROUP BY wp_posts.ID ORDER BY wp_posts.post_date DESC LIMIT
 0, 5
 }}}

-- 
Ticket URL: <http://core.trac.wordpress.org/ticket/17165#comment:19>
WordPress Trac <http://core.trac.wordpress.org/>
WordPress blogging software


More information about the wp-trac mailing list