Forked from luistinygod/gist:9dcb82e1eed60ee7e4b1
Last active
December 14, 2018 10:53
-
-
Save zackkatz/66e9fb2147a9eb1a2f2e to your computer and use it in GitHub Desktop.
For Tim
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( '1' != $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'] ) && '6' == $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
This should be redone using the
gravityview_search_operator
filter instead.