Skip to content

Commit

Permalink
Allow WP_Query 'post_status' parameter to accept an array, as well as…
Browse files Browse the repository at this point in the history
… a singular value and comma separated list. Fixes #16824

git-svn-id: http://svn.automattic.com/wordpress/branches/3.1@18047 1a063a9b-81f0-0310-95a4-ce76da25c4cd
  • Loading branch information
ryan committed May 25, 2011
1 parent 2349eda commit aad5643
Showing 1 changed file with 11 additions and 5 deletions.
16 changes: 11 additions & 5 deletions wp-includes/query.php
Original file line number Diff line number Diff line change
Expand Up @@ -1625,8 +1625,12 @@ function parse_query( $query = '' ) {
$qv['post_type'] = sanitize_key($qv['post_type']);
}

if ( !empty($qv['post_status']) )
$qv['post_status'] = preg_replace('|[^a-z0-9_,-]|', '', $qv['post_status']);
if ( ! empty( $qv['post_status'] ) ) {
if ( is_array( $qv['post_status'] ) )
$qv['post_status'] = array_map('sanitize_key', $qv['post_status']);
else
$qv['post_status'] = preg_replace('|[^a-z0-9_,-]|', '', $qv['post_status']);
}

if ( $this->is_posts_page && ( ! isset($qv['withcomments']) || ! $qv['withcomments'] ) )
$this->is_comment_feed = false;
Expand Down Expand Up @@ -2385,13 +2389,15 @@ function &get_posts() {
$read_private_cap = 'read_private_' . $post_type_cap . 's';
}

if ( isset($q['post_status']) && '' != $q['post_status'] ) {
if ( ! empty( $q['post_status'] ) ) {
$statuswheres = array();
$q_status = explode(',', $q['post_status']);
$q_status = $q['post_status'];
if ( ! is_array( $q_status ) )
$q_status = explode(',', $q_status);
$r_status = array();
$p_status = array();
$e_status = array();
if ( $q['post_status'] == 'any' ) {
if ( in_array('any', $q_status) ) {
foreach ( get_post_stati( array('exclude_from_search' => true) ) as $status )
$e_status[] = "$wpdb->posts.post_status <> '$status'";
} else {
Expand Down

0 comments on commit aad5643

Please sign in to comment.