[wp-trac] [WordPress Trac] #43867: Introduce the ability to control which fields are searched in a search query
WordPress Trac
noreply at wordpress.org
Thu Apr 26 19:04:11 UTC 2018
#43867: Introduce the ability to control which fields are searched in a search
query
------------------------------------------+------------------------------
Reporter: johnbillion | Owner: (none)
Type: feature request | Status: new
Priority: normal | Milestone: Awaiting Review
Component: Query | Version:
Severity: normal | Resolution:
Keywords: needs-patch needs-unit-tests | Focuses:
------------------------------------------+------------------------------
Comment (by birgire):
The {{{parse_search()}}} seems like a good place for
the filter:
{{{
$search_columns = apply_filters( 'post_search_columns', $search_columns,
$q['s'], $this );
}}}
where we can loop over the columns with e.g.:
{{{
$searches = array();
foreach( (array) $search_columns as $search_column ) {
$searches[] = $wpdb->prepare( "({$wpdb->posts}.{$search_column}
$like_op %s)", $like );
}
if( $searches ) {
$search .= "{$searchand}(" . join( " $andor_op", $searches ) .
')';
}
}}}
within the search terms loop.
I will look into this further with unit tests.
--
Ticket URL: <https://core.trac.wordpress.org/ticket/43867#comment:2>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform
More information about the wp-trac
mailing list