I have some users with taxonomy term reference fields. Lets say users can be associated with regions.

When i view the user page i want to see all other users from the same region as the user i am looking at.

I created a views block on users with a contextual filter based on that taxonomy, but i cant get it to work ? Do i need some relationship ??

My Settings for the contextual filter:

  • filter on User: Region (field_region) / that is the taxonomy term reference field in the user
  • provide default value -> user ID from URL

  • specify validatiion criteria -> taxonomy term -> vocabularies "Region" , filter value type -> term name converted to term id

2 Answers 2


You are on the right track, but the contextual filter has to be changed. The user ID is not the region. If you wish to filter on the Region, you must first determine the Region for the user page you are on.

Switch the Provide default value to PHP Code. Then enter something like:

$user = menu_get_object('user');
return $user->field_region['und'][0]['taxonomy_term'];

This will load the term object for the region of the current user, and the filter can then limit the user list based on that term.

To eliminate the current user from this list, set upa second contextual filter in User:UID and set default value to Use ID from URL. Then open up the 'More' settings and check exclude.

  • thx for your answer. do i have to set my first contextual filter to User:Region and then provide the php code ? i tried it and its unfortunaly not working.
    – oll
    Apr 12, 2013 at 21:09
  • If the machine name of your field is field_region and it is a term refernce field, then the code should work fine, if you are embedding the view in a user page. If it is in a node (cotent type), then the code would have to be adjusted.
    – Triskelion
    Apr 12, 2013 at 21:21
  • here is my configuration: -term reference field in user field_region, views block on user, views contextual filter on User:Region and php code you provided. when i go on the user page the view displays no result. do i have to define a relationship and set the contextual filter on a taxonomy term or something ?
    – oll
    Apr 12, 2013 at 21:33

With the help of Triskelion i succeeded. My Steps to adjust the filter:

  • Add Relationship to the taxonomy reference in user. in my case User:Region and require this relationship
  • Add a contextual filter on taxonomy term:name provide default value -> php code : $user = menu_get_object('user');return $user->field_region['und'][0]['taxonomy_term']->name;
  • Add second contextual filter on uid and provide default value user id from url. under more set to exclude the user from its page

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.