Skip to content

Commit 08819b8

Browse files
committed
gcgs-custom-where-clause.php: Added new snippet for custom where clause.
1 parent 45e73a5 commit 08819b8

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

gc-google-sheets/gcgs.php

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
<?php
2+
/**
3+
* Gravity Connect // Google Sheets // Custom Where Clause
4+
*
5+
* This snippet customizes the generation of `where` clauses for Google Sheets queries.
6+
*
7+
* Installation:
8+
* 1. Install per https://gravitywiz.com/documentation/how-do-i-install-a-snippet/
9+
*/
10+
add_filter( 'gcgs_gppa_build_gviz_where_clause', function( $clause, $clauses, $value, $column_letter, $operator, $args ) {
11+
$conditions = array();
12+
13+
// Loop over the $value array and create conditions.
14+
foreach ( $value as $v ) {
15+
if ( ! empty( $v ) ) {
16+
$conditions[] = sprintf( "lower(%s) = '%s'", $column_letter, strtolower( $v ) );
17+
}
18+
}
19+
20+
// Implode the conditions array with ' OR ' to form the $clause.
21+
$clause = implode( ' OR ', $conditions );
22+
23+
return $clause;
24+
}, 10, 6 );

0 commit comments

Comments
 (0)