Last active
August 29, 2015 14:14
-
-
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')
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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