Filter View based on Relationship to Current User Similar to this question, I have an elevated user role (Facilitator) that's associated via profile to a location (content type space) and should see a list of pre-authorized users who have matching profile locations that they can authorize or deny. I've built a view using Views Bulk Operations and have a custom action to change the user role, all of which is working, but I can't figure out how to filter the pre-authorized students by their location matched to the location of the currently logged-in user. Do I have to make a custom filter for this?

EDIT:

The data relationship looks like this:

User -> Profile -> Space

A Profile can have multiple associated Spaces. I want the view to only show users whose associated space(s) match one or more of the associated space(s) of the current logged in user.

In general it doesn't have to be locations, it could be interests, or favorite colors, anything. Any matching of nodes/users by associated data values.
The only way to do this within views is the following:


Make View of using User type
add a Relationship to a Profile2 type (in my case 'Student')
Add Contextual Filter of type profile:student:location  
select "provide default value"
type: "php code"
Use the following code:

global $user;
$profile = profile2_load_by_user($user-&gt;uid,'facilitator');
if (!$profile) { return ''; }
if (!isset($profile-&gt;field_location['und'])) { return ''; }
$locations='';
foreach ($profile-&gt;field_location['und'] as $location) {
  $locations.=','.$location['nid'];
}
return substr($locations,1);

Under "More", Set "Allow Multiple Values" to TRUE
Save your Contextual Filter


Using PHP in this manner, you can load the current User and get associated values to filter by. This may be useful in many other contexts and circumstances.