Wordpress - How to order by post_status?

You can use 'posts_orderby' filter to change the SQL performed.

Note that:

  • using get_posts() you need to set 'suppress_filters' argument of false for the filter to be performed
  • if you don't explicitly set 'post_status' you'll get only published posts (so no much to order)

Code sample:

$filter = function() {
  return 'post_status ASC';
};

add_filter('posts_orderby', $filter);

$posts = get_posts('post_status' => 'any', 'suppress_filters' => false);

remove_filter('posts_orderby', $filter);