Add additional filter for attendees table to allow searching by custom metadata
In the file /event-tickets/src/Tribe/Attendees_Table.php
on line 805 there is a filter of tribe_tickets_search_attendees_by
which allows adding additional searchable fields for attendees. If you can add one more additional filter for the $items
then we would be able to search by any custom meta data that applies to that attendee.
Here is an example:
New Filter that would go on line 806 (or before the other filter, doesn't really matter)
$items = apply_filters( 'tribe_tickets_search_attendees', $items, $search );
Then in my functions.php I have:
```
/*
* Add ticket ID as searchable
/
addfilter('tribeticketssearchattendeesby', function ($searchkeys) {
$search_keys[] = 'ticket_id';
$search_keys[] = 'w_attendee_first_name';
$search_keys[] = 'w_attendee_last_name';
return $search_keys;
}, 999, 1);
/*
* Add contact info to items array
/
addfilter('tribeticketssearchattendees', function ($items) {
foreach ($items as &$item) {
// check if the item contains the "contacts" attendee meta key
if (($item['attendee_meta']['contacts'] ?? false)) {
// make sure the value is a valid id
$id = (abs(filter_var($item['attendee_meta']['contacts']['value'], FILTER_VALIDATE_INT)));
if ($id > 0) {
// load the contact
$contact = new \WTBA\Model\Contact(get_user_by('id', $item['attendee_meta']['contacts']['value']));
// add the new data items to the existing item so they can be searched upon
if ($contact) {
$item['w_attendee_first_name'] = $contact->user->first_name;
$item['w_attendee_last_name'] = $contact->user->last_name;
}
}
}
}
return $items;
}, 999, 1);
```
This can provide pretty powerful functionality with next to no dev time.
