[wp-trac] [WordPress Trac] #16824: WP_Query does not accept post_status argument as an array. Codex says it does.

WordPress Trac wp-trac at lists.automattic.com
Thu Mar 10 17:01:30 UTC 2011


#16824: WP_Query does not accept post_status argument as an array. Codex says it
does.
--------------------------+-----------------------------
 Reporter:  goto10        |      Owner:
     Type:  defect (bug)  |     Status:  new
 Priority:  normal        |  Milestone:  Awaiting Review
Component:  Query         |    Version:  3.1
 Severity:  normal        |   Keywords:
--------------------------+-----------------------------
 I was having problems with `WP_Query` returning posts that had the `trash`
 status even though I was only specifying `publish` and `pending` in my
 `post_status` array param:

 {{{
 $args = array (
         'post_type'      => 'my_post_type',
         'author'         => $current_user->ID,
         'post_status'    => array ( 'publish', 'pending' ),
         'paged'          => $paged,
 );
 $my_query = new WP_Query ( $args );
 }}}

 I found [http://wordpress.org/support/topic/query_posts-and-trash-items-
 strange?replies=2 this] forum post where other folks had the same issue.


 I headed over to #wp-dev, where contributor greuben pointed out that an
 array cannot be used for the value of `post_status`.  I found the
 following in the current release of 3.1:

 {{{
 query.php line 2369 $q_status = explode(',', $q['post_status']);
 }}}

 (greuben pointed out that it's on line 2374 in trunk)


 I was able to get the results I wanted by using a comma separated string
 for the value of the `post_status` arg (thanks greuben):

 {{{
 'post_status'    => 'publish,pending',
 }}}

 I did double check the Codex, and it states that either a
 [http://codex.wordpress.org/Function_Reference/WP_Query#Parameters string
 or an array] can be used:

 {{{
 "post_status (string / array) - use post status. Retrieves posts by Post
 Status, default value is 'publish';"
 }}}

 So, not sure if the Codex is wrong or the core, but I did want to bring
 attention to the issue.

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


More information about the wp-trac mailing list