Posted on

Wildcard matching

Relevanssi Premium 2.10.2 introduces new way to search: wildcard matching. Once the wildcard matching is enabled (it is disabled by default), it introduces two new operators: * and ?.

Using the wildcard operators

The * operator replaces zero or more characters, so searching for w*ess would match “wilderness”, “witness”, “WordPress” and also “wess”.

The ? operator matches exactly one character, so searching for gr?y would match “grey” or “gray”, but not “gravy” or “groovy”.

These operators only work within words. Searching for *ess or gra? will not have the expected results.

The wildcard operators can only be used when the “Keyword matching” setting is not set to “Whole words”, because wildcard matches are not whole word matches.

Enabling wildcard matching

In order to enable the wildcard matching, add a filter function that returns true to the relevanssi_wildcard_search filter hook, like this:

add_filter( 'relevanssi_wildcard_search', '__return_true' );

This one-liner, which you can add for example to the theme functions.php file, will enable the wildcard matching.

Try wildcard matching

Search for wild*d on!

Leave a Reply

Are you a Relevanssi Premium customer looking for support? Please use the Premium support form.

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.