Fine-tuning search results in GravityView with search modifiers

GravityView 2.22 and newer support search modifiers that enable more precise filtering within Views. These modifiers—positive, negative, and exact-match—help refine queries so that results more closely match specified criteria.

1. Positive Search Modifier

The positive search modifier (the character + ) ensures that the search results include entries containing the term following the modifier. This is useful for including specific terms in the results, especially when field values contain similar or related text.

Example of using the positive search modifier:

If your form includes entries with "setting the bar for fine dining" and "Barcelona's best restaurant" as field values, searching for "bar" will return both entries. However, searching for +bar will only return the entry with "setting the bar for fine dining" because the positive search modifier requires that "bar" be a distinct word, not part of a longer word such as "Barcelona."

2. Negative Search Modifier

The negative search modifier (the character - ) excludes entries that contain the term following the modifier from the search results. This is particularly useful for omitting certain terms from the results, streamlining the process of finding entries that do not include specific text.

Example of the negative search modifier

If your form contains entries with "budget-friendly excursions in Barcelona" and "affordable travel options in Spain" field values, searching for "-Barcelona" will return only the entry discussing affordable travel options, excluding the one about budget-friendly excursions in Barcelona.

Search modifiers only take effect when words begin with the modifier; hyphenated words like budget-friendly will not be interpreted as being a negative search for friendly.

3. Exact-Match Search Modifier

The exact-match search modifier ("" ), denoted by quotation marks, targets entries that contain the exact phrase within the marks. This modifier is essential for locating entries with specific terms or phrases, ensuring the search results match exactly.

Example of the exact-match search modifier

If your form contains entries with "gourmet dining in Spain" and "fine dining in Barcelona" field values, searching with the phrase "fine dining" surrounded by quotation marks will only return the entry talking about fine dining in Barcelona.

Customizing Quotation Marks with Developer Filters

You can use the gk/gravityview/common/quotation-marks filter to specify custom quotation marks used for exact-match searches:

add_filter( 'gk/gravityview/common/quotation-marks', function () {
  return [
    'opening' => [ '««' ],
    'closing' => [ '»»' ],
  ];
});
Did this answer your question? Thanks for the feedback There was a problem submitting your feedback. Please try again later.

Still need help? Contact Us Contact Us