Skip to content

Commit 480f3cf

Browse files
authored
Create gppa-multi-value-contains.php
1 parent 5d4a7ae commit 480f3cf

File tree

1 file changed

+28
-0
lines changed

1 file changed

+28
-0
lines changed
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
<?php
2+
/**
3+
* Gravity Perks // Populate Anything // Search by Multiple Values w/ Contains
4+
* https://gravitywiz.com/documentation/gravity-forms-populate-anything/
5+
*
6+
* This snippet extends the "contains" operator to support comparisions where a multi-value field (like a Multi Select)
7+
* is the needle. Typically, the "in" operator would be used for this; however, it has the limitation of only being able
8+
* to match full values rather than checking if any of the needles are contained in the haystack.
9+
*/
10+
add_filter( 'gppa_where_clause', function( $where_clause, $object, $table, $column, $operator, $value ) {
11+
12+
static $_processing;
13+
14+
if ( $_processing || ! is_array( $value ) || $operator !== 'contains' ) {
15+
return $where_clause;
16+
}
17+
18+
$_processing = true;
19+
20+
$clauses = array();
21+
foreach ( $value as $_value ) {
22+
$clauses[] = $object->build_where_clause( $table, $column, $operator, $_value );
23+
}
24+
25+
$_processing = false;
26+
27+
return implode( "\nOR ", $clauses );
28+
}, 10, 6 );

0 commit comments

Comments
 (0)