Can someone tell me why the below code wouldn't be working in my Views filter? I'm trying to accomplish the following:

Show all content of this type if field_targetuser matches logged in user id, but ALSO show all content where field_universal = YES, regardless of what appears in the targetuser id (the logged in user).

global $user;

if($user->uid == $data->field_targetuser || $data->field_universal == "yes")          
{
    return false;
} else {
    return true;
}

I'm currently pasting it into Filter Criteria > Global: PHP

Comments

nitin.k’s picture

You need to make sure $data is a object.


global $user;
if(is_object($data)) {
  if(($user->uid == $data->field_targetuser) || ($data->field_universal == "yes")) {
      return false;
  }
  else {
      return true;
  }
}
else{
  return false;
}