1

I added a term reference field (field_department_term_ref) to user entity (/admin/config/people/accounts/fields), then I need use Views to list all the users with the same term as current logged in user (including current logged in user himself). I referenced this post, But unfortunately there are 2 differences:

  1. Contextual filter "User: field_department_term_ref" can not get the right default value.
  2. If I don't select the "Exclude" checkbox in the MORE section, it will only show current user himself; if not, it will show others users but no current user.
2

By default it provides a way to pass the term from current node and not from user. But there are two different ways to do this :

  1. By Custom Code : Get the term id using $user variable and pass term id to the views_embed_view function which is used to render the views.
  2. Create two views :

    • First view : User list with contextual filter term field that is added in account settings.
    • Second View : User view with contextual filter uid that filters the current logged in user.

      -- In field section add term id field and exclude it from there.

      -- Next field would be the first view which prints the list of users by taking the term argument.

      -- Pass the token of tid in argument section of view field.

To add a views as a field you need a module : Views Field View.

  • I used your second method, it works nicely! Thank you! – fishfree May 22 '15 at 5:52

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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