Skip to content

Instantly share code, notes, and snippets.

@saifsultanc
Created March 21, 2025 12:21
Show Gist options
  • Save saifsultanc/d4bf5080c2a1c7660fe79d077f17e560 to your computer and use it in GitHub Desktop.
Save saifsultanc/d4bf5080c2a1c7660fe79d077f17e560 to your computer and use it in GitHub Desktop.
gcgs_gppa_query_builder_args.php
<?php
add_filter( 'gcgs_gppa_query_builder_args', function( $query_builder_args, $args, $object ) {
/** @var string|string[] */
$filter_value = null;
/** @var array */
$filter = null;
/** @var int */
$filter_group_index = null;
/** @var string */
$property_id = null;
/** @var object */
$field = null;
// phpcs:ignore WordPress.PHP.DontExtract.extract_extract
extract( $args );
// TODO : UPDATE 3 to your targetted form ID.
if ( $field->formId != 3 || $filter['operator'] != 'is' ) {
return $query_builder_args;
}
$column_letter = $object->get_column_letter( $args['primary_property_value'], $property_id );
if ( ! empty( $filter_value ) ) {
$conditions = array();
// Loop over the $value array and create conditions.
foreach ( $filter_value as $v ) {
if ( ! empty( $v ) ) {
$conditions[] = sprintf( "lower(%s) = '%s'", $column_letter, strtolower( $v ) );
}
}
// Remove the last value from the array
array_pop( $query_builder_args['where'][ $filter_group_index ] );
// Add the updated value by Imploding the conditions array with ' OR ' to form the $clause.
$query_builder_args['where'][ $filter_group_index ][] = implode( ' OR ', $conditions );
}
return $query_builder_args;
}, 10, 3);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment