Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions gc-google-sheets/gcgs-custom-where-clause.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?php
/**
* Gravity Connect // Google Sheets // Custom Where Clause
*
* This snippet customizes the generation of `where` clauses for Google Sheets queries.
*
* Installation:
* 1. Install per https://gravitywiz.com/documentation/how-do-i-install-a-snippet/
*/
add_filter( 'gcgs_gppa_build_gviz_where_clause', function( $clause, $clauses, $value, $column_letter, $operator, $args ) {
$conditions = array();

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pending the filter addition

I noticed that this sometimes errored when $value is an empty string

Suggested change
if ( empty( $value ) ) {
return $clause;
}

// Loop over the $value array and create conditions.
foreach ( $value as $v ) {
if ( ! empty( $v ) ) {
$conditions[] = sprintf( "lower(%s) = '%s'", $column_letter, strtolower( $v ) );
}
}

// Implode the conditions array with ' OR ' to form the $clause.
$clause = implode( ' OR ', $conditions );

return $clause;
}, 10, 6 );
Loading