Make WordPress Core

Opened 13 years ago

Closed 13 years ago

Last modified 6 years ago

#16824 closed enhancement (fixed)

WP_Query does not accept post_status argument as an array. Codex says it does.

Reported by: goto10's profile goto10 Owned by: ryan's profile ryan
Milestone: 3.2 Priority: normal
Severity: normal Version: 2.9
Component: Query Keywords: has-patch
Focuses: Cc:


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 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 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.

Attachments (3)

ticket.16824.diff (571 bytes) - added by danielbachhuber 13 years ago.
16824.patch (498 bytes) - added by hakre 13 years ago.
16824.diff (1.5 KB) - added by dd32 13 years ago.

Download all attachments as: .zip

Change History (14)

#1 @nacin
13 years ago

  • Keywords needs-docs needs-patch added
  • Milestone changed from Awaiting Review to Future Release
  • Type changed from defect (bug) to enhancement

The Codex is wrong. It only accepts comma-delimited. I'd like to change that, cause it's lame. Marking as a future enhancement.

#2 @danielbachhuber
13 years ago

  • Cc d@… added

#3 @danielbachhuber
13 years ago

  • Keywords has-patch added; needs-patch removed

#4 @scribu
13 years ago

  • Milestone changed from Future Release to 3.2
  • Version changed from 3.1 to 2.9

#5 @hakre
13 years ago

As it was just reported again (Related: #17014), I added a warning to the codex page.

13 years ago


#6 @bergius
13 years ago

  • Cc bergius.tobias@… added

13 years ago

#7 @dd32
13 years ago

  • Resolution set to fixed
  • Status changed from new to closed

(In [17689]) Allow WP_Query 'post_status' parameter to accept an array, as well as a singular value and comma separated list. Fixes #16824

#8 @dd32
13 years ago

  • Keywords needs-docs removed

#9 @ryan
13 years ago

  • Owner set to ryan

In [18047]:

Allow WP_Query 'post_status' parameter to accept an array, as well as a singular value and comma separated list. Fixes #16824

#10 @info2grow
6 years ago

  • Type changed from enhancement to defect (bug)

This issue persists in 4.9.4

Version 0, edited 6 years ago by info2grow (next)

#11 @dd32
6 years ago

  • Type changed from defect (bug) to enhancement

@info2grow This ticket was fixed 7 years ago. WP_Query does indeed accept the parameter as an array.

If you require code support, the WordPress forums are the place to go:
If you're experiencing a bug in WordPress or would like to propose a new feature/enhancement to an existing functionality, please create a new ticket on this Trac instead.

Note: See TracTickets for help on using tickets.