Hide field results not matching exposed filter I have an Autocomplete (Tags style) field with multiple values in the field.

I'm using exposed filters to display nodes with one or more values in the Autocomplete field matching the filters.

I want the node field to display only the matched values, not all of them when rendered in a view.

For example. Say I have three nodes with the following field values:



Then I apply exposed filters of Orange and Grape. This results in the following (as Node A does not contain these values):

 

What I want is values not in the exposed filters to also disappear, so the user can see exactly what selected fields matched the node. Like so:



I assume this can be done using the Global PHP field, but really need some help to figure it out.
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(&amp;$view) {
    // Set the view we want to work with
    if ($view-&gt;name=='your_view') {
        // print out your array, so you know what you have (comment out in live site)
        drupal_set_message('&lt;pre&gt;' . print_r($view-&gt;result, TRUE) . '&lt;/pre&gt;'); 
        // Check to see if the filter has been triggered, otherwise you will get errors
        if (isset($view-&gt;exposed_input['exposed_filter_name'])) {
            foreach($view-&gt;result as $result_id =&gt; $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-&gt;field_your_field as $field_id =&gt; $field_val) {
                    //find the TID related to your result
                    $field_tid = $result-&gt;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-&gt;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-&gt;field_your_field)) !== false) {
                            // And remove it
                            unset($result-&gt;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-&gt;field_your_field = array_values($result-&gt;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