diff --git a/wp-includes/post.php b/wp-includes/post.php index e6a73717a4..0254554bfb 100644 --- a/wp-includes/post.php +++ b/wp-includes/post.php @@ -1573,9 +1573,10 @@ function wp_match_mime_types($wildcard_mime_types, $real_mime_types) { * @since 2.5.0 * * @param string|array $mime_types List of mime types or comma separated string of mime types. + * @param string $table_alias Optional. Specify a table alias, if needed.  * @return string The SQL AND clause for mime searching. */ -function wp_post_mime_type_where($post_mime_types) { +function wp_post_mime_type_where($post_mime_types, $table_alias = '') { $where = ''; $wildcards = array('', '%', '%/%'); if ( is_string($post_mime_types) ) @@ -1603,9 +1604,9 @@ function wp_post_mime_type_where($post_mime_types) { return ''; if ( false !== strpos($mime_pattern, '%') ) - $wheres[] = "post_mime_type LIKE '$mime_pattern'"; + $wheres[] = empty($table_alias) ? "post_mime_type LIKE '$mime_pattern'" : "$table_alias.post_mime_type LIKE '$mime_pattern'"; else - $wheres[] = "post_mime_type = '$mime_pattern'"; + $wheres[] = empty($table_alias) ? "post_mime_type = '$mime_pattern'" : "$table_alias.post_mime_type = '$mime_pattern'"; } if ( !empty($wheres) ) $where = ' AND (' . join(' OR ', $wheres) . ') '; diff --git a/wp-includes/query.php b/wp-includes/query.php index 71200b9388..7467fbfe9d 100644 --- a/wp-includes/query.php +++ b/wp-includes/query.php @@ -2026,13 +2026,14 @@ class WP_Query { $post_ids = get_objects_in_term($term_ids, $taxonomy); if ( !is_wp_error($post_ids) && !empty($post_ids) ) { $whichcat .= " AND $wpdb->posts.ID IN (" . implode(', ', $post_ids) . ") "; - if ( '' === $post_type ) { + if ( empty($post_type) ) { $post_type = 'any'; $post_status_join = true; } elseif ( in_array('attachment', (array)$post_type) ) { $post_status_join = true; } - $q['post_status'] = 'publish'; + if ( empty($q['post_status']) ) + $q['post_status'] = 'publish'; } else { $whichcat = " AND 0 "; } @@ -2083,8 +2084,10 @@ class WP_Query { // MIME-Type stuff for attachment browsing - if ( isset($q['post_mime_type']) && '' != $q['post_mime_type'] ) - $whichmimetype = wp_post_mime_type_where($q['post_mime_type']); + if ( isset($q['post_mime_type']) && '' != $q['post_mime_type'] ) { + $table_alias = $post_status_join ? $wpdb->posts : ''; + $whichmimetype = wp_post_mime_type_where($q['post_mime_type'], $table_alias); + } $where .= $search . $whichcat . $whichauthor . $whichmimetype;