[wp-trac] [WordPress Trac] #14645: Support for multiple meta_key => meta_value pairs in WP_Query

WordPress Trac wp-trac at lists.automattic.com
Fri Aug 20 16:27:33 UTC 2010


#14645: Support for multiple meta_key => meta_value pairs in WP_Query
-------------------------+--------------------------------------------------
 Reporter:  joehoyle     |        Owner:                 
     Type:  enhancement  |       Status:  reopened       
 Priority:  normal       |    Milestone:  Awaiting Review
Component:  Query        |      Version:                 
 Severity:  normal       |   Resolution:                 
 Keywords:               |  
-------------------------+--------------------------------------------------

Comment(by joehoyle):

 13 lines!

 SQL Query generated for: {{{'meta_key=address&meta_value=London'}}} Before
 patch:

 {{{SELECT SQL_CALC_FOUND_ROWS  wp_posts.* FROM wp_posts  JOIN wp_postmeta
 ON (wp_posts.ID = wp_postmeta.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 = 'address' AND wp_postmeta.meta_value
 = 'London'  GROUP BY wp_posts.ID ORDER BY wp_posts.post_date DESC LIMIT 0,
 10}}}

 Same as above (with patch):

 {{{SELECT SQL_CALC_FOUND_ROWS  wp_posts.* FROM wp_posts  JOIN wp_postmeta
 ON (wp_posts.ID = wp_postmeta.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 = 'address' AND wp_postmeta.meta_value
 = 'London'  GROUP BY wp_posts.ID ORDER BY wp_posts.post_date DESC LIMIT 0,
 10}}}

 (they are the same :P)

 SQL Query generated for: {{{array( 'meta_key' => array( 'address',
 'rating' ), 'meta_value' => array( 'London', '5'), 'meta_compare' =>
 array( '=', '<' ) )}}} After patch:

 {{{SELECT SQL_CALC_FOUND_ROWS  wp_posts.* FROM wp_posts  JOIN wp_postmeta
 ON (wp_posts.ID = wp_postmeta.post_id)  JOIN wp_postmeta as wp_postmeta_1
 ON (wp_posts.ID = wp_postmeta_1.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 = 'address'
 AND wp_postmeta_1.meta_key = 'rating' AND wp_postmeta.meta_value =
 'London' AND wp_postmeta_1.meta_value < '5'  GROUP BY wp_posts.ID ORDER BY
 wp_posts.post_date DESC LIMIT 0, 10}}}

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


More information about the wp-trac mailing list