Views filter on field being either empty or equal to uid I have a views filter on a particular field being empty (Is empty (NULL)).

However, I would like to have it check on the field being either empty or equal to the current user's uid. I would like to do this programmatically in a custom module, so without installing a contributed module.

The field in question is $node-&gt;field_quality_personal[LANGUAGE_NONE][0]['value']. So this field can be either empty, or it can contain a uid.
I found the way to fix this. The answer is twofold:

First create two filters: one for the field being empty and one for the field being equal to the string "uid". Then as a Filter Criteria option, choose And/Or, Rearrange and add the Or condition:



This is the result:



Second implement hook_views_query_alter() to replace the "uid" string we added earlier with the actual user uid:

/**
 * Implements hook_views_query_alter().
 *
 * Search for 'personal' field to be empty or equal to uid.
 */
function example_views_query_alter(&amp;$view, &amp;$query) {
  if ($view-&gt;name == 'myview') {
    foreach ($query-&gt;where as &amp;$condition_group) {
      foreach ($condition_group['conditions'] as &amp;$condition) {
        if ($condition['field'] == 'table.field_quality_personal' &amp;&amp; $condition['value'] == 'uid') {
          global $user;
          $condition['value'] = $user-&gt;uid;
        }
      }
    }
  }
}


That's it!