Skip to main contentSkip to footer

Relevanssi Premium 2.10.2 introduces a 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' );

Add this one-liner to your site to enable wildcard matching.

Try wildcard matching

Search for wild*d on Relevanssi.com!

Your account

Not logged in. Log in to see your license details.

Search

Popular Resources

How to index parent categories

Suppose you have a parent category with no products in it but a child category does. If you search by the parent category can relevanssi be set up to show the products in the child category? Cars > Wiper Blades. A search for cars shows wiper blade products. By default…

Polylang attachment searching
If Polylang is in use and you haven’t enabled “Media translation“, your attachment files won’t have a language. That’s fine,…
Direct access to the query engine

Relevanssi can’t be used in any situation, because it checks the presence of search with the is_search() function. This causes some unfortunate limitations and reduces the general usability of the plugin. You can, however, access the query engine directly. There’s a function called relevanssi_do_query(), which can be used to do search queries…

Related Posts:

Comment Section:

2 Comments. Leave new

  • Interesting… I was expecting two question marks to be treated as two single character wildcards.
    Instead, searching for: abc??def
    is the same as searching for: abc* def

    Reply
    • Correct: the ? operator can only appear between two word characters, otherwise it’s interpreted as a regular question mark. You can use two question marks, but they cannot be next to each other.

      Reply

Leave a Reply

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

Fill out this field
Fill out this field
Please enter a valid email address.
You need to agree with the terms to proceed