Office is content type

User accounts have a Node reference to Office, field_office.

I need to create a view which displays Office->name where Office->nid = Current_User->field_office

I can't believe something this simple is so difficult to setup. I've setup another view where User->field_office = Project->field_office. In that case I created two relationships:

Field: Office
(field_office) Content: Office (field_office) - reverse (to User)

And a Contextual Filter

(field_office) User: Uid

Where the default value is current logged in user's uid.

That was easier since both fields are the same (field_office). But I can't figure out how to link a field to a Content nid.


It would be simple if I could just create a Contextual filter on Content: nid and set the default value to User: field_office. I can't figure out how to do that though. The only contextual filter option which might support that is PHP code, but what would I tell it to return? This doesn't seem to work (breaks AJAX)

$user_data = user_load($user->uid);
return $user_data->field_office['und']['0']['value'];

1 Answer 1


Figured it out. Had to create a contextual filter on Content: nid and set the default value to PHP code:

$uid = $GLOBALS['user']->uid;
$user_data = user_load($uid);
return $user_data->field_office['und'][0]['nid'];

Really weird that this isn't easier to do.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.