Skip to content

Instantly share code, notes, and snippets.

@luistinygod
Last active August 29, 2015 14:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save luistinygod/9dcb82e1eed60ee7e4b1 to your computer and use it in GitHub Desktop.
Save luistinygod/9dcb82e1eed60ee7e4b1 to your computer and use it in GitHub Desktop.
Force GravityView search to be exact for a certain field (Operator 'is' instead of 'like')
<?php
/**
* Place this in your theme's functions.php
* Please adapt the form_id and the field key to your own case.
* This is intended to force GravityView to search for the exact value instead of be more relaxed (default search uses operator LIKE)
*
*/
add_filter( 'gravityview_fe_search_criteria', 'my_gv_exact_search', 20, 2 );
function my_gv_exact_search( $search_criteria, $form_id = '' ) {
if( '80' != $form_id ) { return $search_criteria; }
if( empty( $search_criteria['field_filters'] ) || !is_array( $search_criteria['field_filters'] ) ) { return $search_criteria; }
foreach( $search_criteria['field_filters'] as $k => $filter ) {
if( !empty( $filter['key'] ) && '5' == $filter['key'] ) {
$search_criteria['field_filters'][ $k ]['operator'] = 'is';
break;
}
}
return $search_criteria;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment