apply_filters( 'relevanssi_term_where', string $term_where, string $term )

This filter hook filters the WHERE condition for the Relevanssi MySQL query.


(string) The WHERE part of the query for the terms.

(string) The search term.

More information

In the function relevanssi_generate_term_where(), Relevanssi creates the part of the MySQL query that concerns the search term (if the search query has multiple words, there’s one of these for each word).

The term query depends on the keyword matching settings: it’s different if you want partial or whole word matching. Relevanssi chooses which template to use and then replaces the term in the template. After that, Relevanssi passes the query through this filter hook.

For partial matching, the term query looks like this:

(relevanssi.term LIKE '#term#%' OR relevanssi.term_reverse LIKE CONCAT(REVERSE('#term#'), '%'))

For whole word matching, it’s:

relevanssi.term = '#term#'

Finally, for termless searches, it’s:

relevanssi.term = relevanssi.term

Relevanssi Premium uses this filter hook internally to create the wildcard search: the wildcard operators ? and * are replaced with the MySQL equivalents _ and %.