I managed to do this by creating a module that implements hook_views_pre_render()
Your field values will need to be taxonomy references for this to work, like so:
function MyModule_views_pre_render(&$view) {
// Set the view we want to work with
if ($view->name=='your_view') {
// print out your array, so you know what you have (comment out in live site)
drupal_set_message('<pre>' . print_r($view->result, TRUE) . '</pre>');
// Check to see if the filter has been triggered, otherwise you will get errors
if (isset($view->exposed_input['exposed_filter_name'])) {
foreach($view->result as $result_id => $result) {
// cycle through each view result row, check that each result exists in the exposed filter. if it does not, then remove it.
foreach ($result->field_your_field as $field_id => $field_val) {
//find the TID related to your result
$field_tid = $result->field_your_field[$field_id]['raw']['target_id'];
// Check if the TID is missing from the exposed filter values
if (array_search($field_tid, $view->exposed_input['exposed_filter_name']) === false) {
// Now look through your field values to find the TID missing from the values
if (($key = array_search($field_val, $result->field_your_field)) !== false) {
// And remove it
unset($result->field_your_field[$key]);
}
}
}
}
}
}
// Finally re-number array to account for missing elements - i.e. [1],[3],[4],[6] to [1],[2],[3],[4] (optional, but tidier)
$result->field_your_field = array_values($result->field_your_field);
}
Note that field_your_field
is written like that because you need to append an extra field_
to the machine name. e.g. machine name field_my_field
would become field_field_my_field