How to search for an exact match
GravityView's current search functionality doesn't use an exact match, it uses the contains operator, so if you search for the word "Kansas", results containing that word, like "Arkansas", will also show up:
If you wish to change the search functionality to look for an exact match, then you need the function below:
// This globally changes Search Widget search operator from "contains" to "is" add_filter( 'gravityview_search_operator', function() { return 'is'; });
Here's the end result:
Searching with empty values
If you have more than 2 fields on your Search Bar and leave one empty, the search will return the same results as before:
But if you want to require users to fill all fields in order for results to appear, then you'll need to also add this other code snippet below:
// This disallows empty field values add_filter( 'gravityview/search/ignore-empty-values', function() { return false; });
This way, the search won't return any results until both fields are filled:
This is perfect to restrict entry results for only those users that know particular details from their submission, like an SSN number in conjunction with a Zip Code or date of birth.
Defining strict matches for particular fields
If you need to target just a specific field from a specific form, then the code is a little bit more complex. To achieve that, we've created a simple plugin that you can download here. You'll need to modify the Form ID and Field IDs inside that plugin's code using the plugin editor on your WordPress Dashboard:
Please contact our support if you need further assistance.