Programmatically Access custom user field I added a Node-reference field (machine name: field_node) to all users at:

example.com/admin/config/people/accounts/fields/


I am now working in a custom module &amp; hook_node_access 

How do I access the Node-reference field programmatically when the user is logged in?
You can get field values from any entity with field_get_items(); the logged in user is available in the global $user object, and to load fields onto that object you can use user_load().

Put those together and you get something like this:

// Get a fully loaded entity object for the logged in user.
$account = user_load($GLOBALS['user']-&gt;uid);

// Extract the field items
$field_items = field_get_items('user', $account, 'field_node');
if ($field_items) {
  // This will be 'target_id' if you're using the Entity Reference module, 
  // or 'nid' if you're using References
  $column_name = '?'; 

  $nid = $field_items[0][$column_name];
}


That's the abstract code if you like.

It's worth bearing in mind that hook_node_access() is passed an $account object already (which will be the logged in user if the access check is happening for them) so you would probably be better off using that to check against. You might still need to run it through user_load(), it'll be easy enough to check that with a bit of debugging.