Skip to content

Instantly share code, notes, and snippets.

@zackkatz
Created July 29, 2021 17:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save zackkatz/7acb41577deae674916ec8cacb42cee2 to your computer and use it in GitHub Desktop.
Save zackkatz/7acb41577deae674916ec8cacb42cee2 to your computer and use it in GitHub Desktop.
GravityView - Exact-match search (not fuzzy) for a specific field and View
<?php
/**
* Return strict "is" comparison operator when processing a search on a specific View and field.
*
* @param string $operator Existing search operator
* @param array $filter array with `key`, `value`, `operator`, `type` keys
* @param \GV\View $view The View we're operating on.
*
* @return string
*/
add_filter( 'gravityview_search_operator', function ( $operator, $filter, $view ) {
// Only run on /suggested-rule-change-comments/
if( 7768 !== $view->ID ) {
return $operator;
}
if ( '7' === $filter['key'] ) {
return $operator;
}
return 'is';
}, 10, 3 );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment