I have a view that I need to filter based on the current logged in user, however a secondary entity reference is in-between the two. Pretty sure I need to add in PHP contextual filter code but not exactly sure what is needed.


  1. inventory has an entity reference to retail_location.
  2. retail_location has an entity reference to users.
  3. I need to display inventory based on the retail_location of the logged in user.


1 Answer 1


Was able to get it working using the following code, it does however only allow for one retail location, which is all I need for this scenario.

  global $user;
  $query = new EntityFieldQuery;
  $query->entityCondition('entity_type', 'node')
      ->entityCondition('bundle', 'rnm_principal')
      ->fieldCondition('field_principal_retailer', 'target_id', array($user->uid));
  $results = $query->execute();
  return current($results['node'])->nid;

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.