Last active
March 13, 2025 10:09
-
-
Save saifsultanc/2b2540992da16bf314107a04479bef69 to your computer and use it in GitHub Desktop.
gc-google-sheets/gcgs-gppa-custom-query-builder-args.php
This file contains hidden or 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 | |
| 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 4 to your targetted field ID. | |
| // TODO : UPDATE 141 to your targetted form ID. | |
| if ( $field->id != '4' || $field->formId != 141 || $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 ) ); | |
| } | |
| } | |
| // Implode the conditions array with ' OR ' to form the $clause. | |
| $query_builder_args['where'][ $filter_group_index ][ $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