Make WordPress Core

Ticket #38099: 38099.patch

File 38099.patch, 884 bytes (added by chriseverson, 7 years ago)

Patch for this issue using a new filter "wp_search_exclusion" with a default of true

  • wp-includes/class-wp-query.php

     
    13231323                $n = ! empty( $q['exact'] ) ? '' : '%';
    13241324                $searchand = '';
    13251325                $q['search_orderby_title'] = array();
     1326
     1327                /**
     1328                 * Filters whether to exclude search terms preceded with a hyphen
     1329                 *
     1330                 * @since 4.7.0
     1331                 *
     1332                 * @param bool Whether the search query exclude terms preceded with a hyphen
     1333                 */
     1334                $hyphen_exclusion = apply_filters( 'wp_search_exclusion', '__return_true' );
     1335
    13261336                foreach ( $q['search_terms'] as $term ) {
    13271337                        // Terms prefixed with '-' should be excluded.
    13281338                        $include = '-' !== substr( $term, 0, 1 );
    1329                         if ( $include ) {
     1339                        if ( $include || ! $hyphen_exclusion ) {
    13301340                                $like_op  = 'LIKE';
    13311341                                $andor_op = 'OR';
    13321342                        } else {