-
-
Save doekenorg/5755c563e54f02af7e31e90cfbfc2a14 to your computer and use it in GitHub Desktop.
Filter results with sets via URL
This file contains 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 | |
// .. | |
// filetrs for form ID: 1 | |
add_filter('gfexcel_output_search_criteria_1', function ($search) { | |
// Add a group with filters | |
// An operator can be: <, >, =, >=, <=, <>, contains, like, is, is not, in, not in | |
$filters['groupA'] = [ | |
// mode says: <mode> of the following rules should apply for me to filter | |
'mode' => 'any', | |
// or 'all'. 'all' is default, and then this can be omitted. | |
// [Field id, operator, value] | |
['1', 'contains', 'Onion'], | |
// a single field with a value containing "Onion" | |
['2.4', 'contains', 'Peanut'], | |
// A multipart field (like name or address) (2) where the subfield (4) contains "Peanut" | |
]; | |
// Retrieve the filterset from the url (?subset=<filfter-group>) | |
$subset = rgar($filters, rgar($_GET, 'subset'), []); | |
if (!$subset) { | |
// none found, so no filtering. | |
return $search; | |
} | |
// remap the filters so it's following the rules. | |
$field_filters = rgar($search, 'field_filters', []); | |
$search['field_filters'] = array_merge($field_filters, array_map(function ($row) { | |
if (!is_array($row)) { | |
return $row; | |
} | |
list($key, $operator, $value) = $row; | |
return compact('key', 'operator', 'value'); | |
}, $subset)); | |
return $search; | |
}); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
@websherpa Is this something you can work with?
It's not as nice as I would like it to be, but I can't seem to find the time to do it less verbose without introducing some new files.