[wp-trac] [WordPress Trac] #17014: Passing post_status an array for a new WP_Query throws an error

WordPress Trac wp-trac at lists.automattic.com
Fri Apr 1 04:49:26 UTC 2011


#17014: Passing post_status an array for a new WP_Query throws an error
--------------------------+-----------------------------
 Reporter:  drebabels     |      Owner:
     Type:  defect (bug)  |     Status:  new
 Priority:  normal        |  Milestone:  Awaiting Review
Component:  Query         |    Version:  3.1
 Severity:  minor         |   Keywords:
--------------------------+-----------------------------
 According to the WP_Query documentation
 (http://codex.wordpress.org/Function_Reference/WP_Query#Type_.26_Status_Parameters)
 the post_status parameter takes either an array or string. However when
 you pass it an array like so

 {{{
 $args = array (
         'post_status' => array('inherit','publish')
 );
 $query = new WP_Query( $args );
 }}}

 The following two errors are thrown:

 Warning: explode() expects parameter 2 to be string, array given in
 /Users/ender/Sites/soompi3k_trunk/htdocs/wp-includes/query.php on line
 2369

 Warning: in_array() expects parameter 2 to be array, null given in
 /Users/ender/Sites/soompi3k_trunk/htdocs/wp-includes/query.php on line
 2378

 And the SQL query looks like this:

 SELECT SQL_CALC_FOUND_ROWS  wp_posts.* FROM wp_posts  WHERE 1=1  AND
 wp_posts.post_type = 'post'  ORDER BY wp_posts.post_date DESC LIMIT 0, 10

 But pass in a comma separated string like so

 {{{
 $args = array (
         'post_status' => 'inherit, publish'
 );
 $query = new WP_Query( $args );
 }}}

 No errors are thrown and the resulting SQL query is what I would expect:

 SELECT SQL_CALC_FOUND_ROWS  wp_posts.* FROM wp_posts  WHERE 1=1  AND
 wp_posts.post_type = 'post' AND (wp_posts.post_status = 'publish' OR
 wp_posts.post_status = 'inherit')  ORDER BY wp_posts.post_date DESC LIMIT
 0, 10

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


More information about the wp-trac mailing list