I am creating a front end dashboard where I need to show all the posts by the current user. So, I need to show posts in all states, mainly published, trashed and the pending. I am now using a simple query but it is returning only the published posts.

$query = array(
    'post_type' => 'my-post-type',
    'post_author' => $current_user->ID              

Can anyone help? What else do I need to do?

  • 4
    Have you tried using the post_status parameter, ie. 'post_status' => 'any'? – t31os Mar 30 '11 at 13:50
  • 2
    I strongly recommend using WP_Query pre_get_posts or get_posts instead of query_posts. Never use query_posts – Tom J Nowell Apr 16 '13 at 12:45
  • @TomJNowell: that was way back :) I use WP_Query most ofter now.. – Sisir Apr 17 '13 at 17:22
  • @Sisir be careful, use WP_Query for front-end, and get_posts for admin queries as there is an issue with wp_reset_postdata (see the note and ticket on this issue). – Aurovrata Jan 30 '17 at 8:10

You can use the post_status parameter:

* 'publish' - a published post or page
* 'pending' - post is pending review
* 'draft' - a post in draft status
* 'auto-draft' - a newly created post, with no content
* 'future' - a post to publish in the future
* 'private' - not visible to users who are not logged in
* 'inherit' - a revision. see get_children.
* 'trash' - post is in trashbin. added with Version 2.9. 

I'm not sure that it accepts 'any' so use and array with all of the types you want:

$query = array(
    'post_type' => 'my-post-type',
    'post_author' => $current_user->ID,
    'post_status' => array('publish', 'pending', 'draft', 'auto-draft', 'future', 'private', 'inherit', 'trash')    
$loop = new WP_Query($query);

while ( $loop->have_posts() ) : $loop->the_post();
  • 5
    You could also use get_post_stati() to get all statuses, including custom ones. – fuxia Jan 31 '13 at 11:52
  • 4
    A wasted opportunity to kill off a query_posts call... – Tom J Nowell Apr 16 '13 at 12:45
  • too bad we can't do something like this 'post_status' => array( '!inherit' ); (to indicate any post_status other than inherit) – aequalsb Jan 3 '17 at 1:17
  • @aequalsb what about 'post_status' => array_diff(get_post_stati(), ['inherit']); – Cheslab Oct 29 '18 at 13:05

There is simple way, how to get all posts with any status:

$articles = get_posts(
  'numberposts' => -1,
  'post_status' => 'any',
  'post_type' => get_post_types('', 'names'),

Now you can iterate throughout all posts:

foreach ($articles as $article) { 
 echo $article->ID . PHP_EOL; //...
  • 2
    $posts and $post conflict with Wordpress' own variable names. If you are using this code to put something in other than the primary (main content) div, this will overwrite what would have been shown in main. If your intention really is to completely replace the original query results, this is what you want, of course. But it's still a good idea to rename the $posts and $post variables. – Henrik Erlandsson Feb 3 '14 at 7:54
  • 4
    @Henrik i am not intending to diminish your comment at all (your logic is sound and safe), but i consider using $post/$posts as perfectly acceptable inside a function without access to the global $post/$posts variables -- because it helps me maintain logic during development. – aequalsb Jan 3 '17 at 1:14

The WP_Query class method ->query() accepts an any argument for post_status. See wp_get_associated_nav_menu_items() for a proof.

The same goes for get_posts() (which is just a wrapper for above call).

  • 3
    From the WP_Query docs: 'any' - retrieves any status except those from post types with 'exclude_from_search' set to true. (There's a typo there, they actually mean post statuses instead of post types.) This means statuses auto-draft and trash are excluded. – Tamlyn Apr 15 '13 at 12:50
  • @Tamlyn Afaik, this is no typo. It retrieves any status from post types that are publicly available. Status are just terms. They got no public or private property themselves. You could disable a taxonomy with disabling the query_var... for whatever reason one would do that. Sidenote: The plural of post status is.... – kaiser Apr 15 '13 at 14:30
  • 1
    If you trace through the code (often easier than reading the docs, I find) you can see that WP_Query#get_posts() calls get_post_stati() which filters $wp_post_statuses for values where exclude_from_search is true then it excludes posts with these statuses from the query. There's a similar process for post types when post_type is set to 'any'. – Tamlyn Apr 16 '13 at 11:15
  • @Tamlyn After checking the contents of the $wp_post_statuses property, I have to admit that you're right :) – kaiser Apr 16 '13 at 12:07
  • doesn't work for trash status. – Maxwell s.c Dec 10 '18 at 20:56

Even if you pass any as post_status, you still will not get the post in the result if all of the following conditions are true:

  1. A single post is being queried. An example of this would be querying by name, i.e. the slug.
  2. The post has a post status that is not public.
  3. The client does not have an active admin session, i.e. you are not currently logged in.


Query explicitly for every status. For example, to query for stati which are not trash or auto-draft (it's pretty unlikely that you want those), you could do something like this:

$q = new WP_Query([
    /* ... */
    'post_status' => get_post_stati(['exclude_from_search' => false]),

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.