Make WordPress Core

Ticket #22744: 22744.4.diff

File 22744.4.diff, 2.1 KB (added by joemcgill, 8 years ago)
  • src/wp-includes/class-wp-query.php

    diff --git src/wp-includes/class-wp-query.php src/wp-includes/class-wp-query.php
    index 9590406..a6cd1c2 100644
    class WP_Query { 
    13411341                        }
    13421342
    13431343                        $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
    13451352                        $searchand = ' AND ';
    13461353                }
    13471354
    class WP_Query { 
    20682075                        }
    20692076                }
    20702077
    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' ] ) ) {
    20722079                        $groupby = "{$this->db->posts}.ID";
    20732080                }
    20742081
    class WP_Query { 
    21172124                }
    21182125                $where .= $search . $whichauthor . $whichmimetype;
    21192126
     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
    21202132                if ( ! empty( $this->meta_query->queries ) ) {
    21212133                        $clauses = $this->meta_query->get_sql( 'post', $this->db->posts, 'ID', $this );
    21222134                        $join   .= $clauses['join'];