diff --git src/wp-includes/class-wp-query.php src/wp-includes/class-wp-query.php
index 9590406..a6cd1c2 100644
|
|
class WP_Query { |
1341 | 1341 | } |
1342 | 1342 | |
1343 | 1343 | $like = $n . $this->db->esc_like( $term ) . $n; |
1344 | | $search .= $this->db->prepare( "{$searchand}(({$this->db->posts}.post_title $like_op %s) $andor_op ({$this->db->posts}.post_excerpt $like_op %s) $andor_op ({$this->db->posts}.post_content $like_op %s))", $like, $like, $like ); |
| 1344 | |
| 1345 | // If this is a search for attachments, inlcude the filename in the search. |
| 1346 | if ( 'attachment' === $q['post_type'] ) { |
| 1347 | $search .= $this->db->prepare( "{$searchand}(({$this->db->posts}.post_title $like_op %s) $andor_op ({$this->db->posts}.post_excerpt $like_op %s) $andor_op ({$this->db->posts}.post_content $like_op %s) $andor_op ({$this->db->postmeta}.meta_key = '_wp_attached_file' AND {$this->db->postmeta}.meta_value $like_op %s))", $like, $like, $like, $like ); |
| 1348 | } else { |
| 1349 | $search .= $this->db->prepare( "{$searchand}(({$this->db->posts}.post_title $like_op %s) $andor_op ({$this->db->posts}.post_excerpt $like_op %s) $andor_op ({$this->db->posts}.post_content $like_op %s))", $like, $like, $like ); |
| 1350 | } |
| 1351 | |
1345 | 1352 | $searchand = ' AND '; |
1346 | 1353 | } |
1347 | 1354 | |
… |
… |
class WP_Query { |
2068 | 2075 | } |
2069 | 2076 | } |
2070 | 2077 | |
2071 | | if ( !empty( $this->tax_query->queries ) || !empty( $this->meta_query->queries ) ) { |
| 2078 | if ( ! empty( $this->tax_query->queries ) || ! empty( $this->meta_query->queries ) || ( $this->is_search && 'attachment' === $q[ 'post_type' ] ) ) { |
2072 | 2079 | $groupby = "{$this->db->posts}.ID"; |
2073 | 2080 | } |
2074 | 2081 | |
… |
… |
class WP_Query { |
2117 | 2124 | } |
2118 | 2125 | $where .= $search . $whichauthor . $whichmimetype; |
2119 | 2126 | |
| 2127 | // Modify the JOIN clause for attachment searches. |
| 2128 | if ( $this->is_search && 'attachment' === $q[ 'post_type' ] ) { |
| 2129 | $join .= " INNER JOIN {$this->db->postmeta} ON ( {$this->db->posts}.ID = {$this->db->postmeta}.post_id )"; |
| 2130 | } |
| 2131 | |
2120 | 2132 | if ( ! empty( $this->meta_query->queries ) ) { |
2121 | 2133 | $clauses = $this->meta_query->get_sql( 'post', $this->db->posts, 'ID', $this ); |
2122 | 2134 | $join .= $clauses['join']; |