#17014 closed defect (bug) (duplicate)
Passing post_status an array for a new WP_Query throws an error
Reported by: | drebabels | Owned by: | |
---|---|---|---|
Milestone: | Priority: | normal | |
Severity: | minor | Version: | |
Component: | Query | Keywords: | |
Focuses: | Cc: |
Description
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
Just as a precautionary mention, the Codex is not official documentation and cannot always be trusted. The Codex is community supplied documentation and has been known to often contain incorrect information.
In any case, this is a duplicate of a ticket that already has a patch. Closing as such. See #16824