diff --git a/wp-includes/post.php b/wp-includes/post.php
index 5dfe747a87..afdd29cb5d 100644
--- a/wp-includes/post.php
+++ b/wp-includes/post.php
@@ -86,12 +86,14 @@ function create_initial_post_types() {
register_post_status( 'trash', array( 'label' => _x('Trash', 'post'),
'public' => true,
+ 'exclude_from_search' => true,
'_builtin' => true,
'label_count' => _n_noop('Trash (%s)', 'Trash (%s)')
) );
register_post_status( 'auto-draft', array( 'label' => _x('Auto-Draft', 'post'),
'public' => false,
+ 'exclude_from_search' => true,
'_builtin' => true,
'label_count' => _n_noop('Auto-Draft (%s)', 'Auto-Drafts (%s)')
) );
diff --git a/wp-includes/query.php b/wp-includes/query.php
index c3417df308..4b352b728f 100644
--- a/wp-includes/query.php
+++ b/wp-includes/query.php
@@ -2097,9 +2097,10 @@ class WP_Query {
$q_status = explode(',', $q['post_status']);
$r_status = array();
$p_status = array();
+ $e_status = array();
if ( $q['post_status'] == 'any' ) {
- // @todo Use register_post_status() data to determine which states should be excluded.
- $r_status[] = "$wpdb->posts.post_status <> 'trash'";
+ foreach ( get_post_stati( array('exclude_from_search' => true) ) as $status )
+ $e_status[] = "$wpdb->posts.post_status <> '$status'";
} else {
foreach ( get_post_stati() as $status ) {
if ( in_array( $status, $q_status ) ) {
@@ -2116,6 +2117,9 @@ class WP_Query {
unset($p_status);
}
+ if ( !empty($e_status) ) {
+ $statuswheres[] = "(" . join( ' AND ', $e_status ) . ")";
+ }
if ( !empty($r_status) ) {
if ( !empty($q['perm'] ) && 'editable' == $q['perm'] && !current_user_can("edit_others_{$post_type_cap}s") )
$statuswheres[] = "($wpdb->posts.post_author = $user_ID " . "AND (" . join( ' OR ', $r_status ) . "))";