0

I'm running a D7 system where every user has a skills field which is a taxonomy field.

How do I create a view to pull users where they have/share same skills (taxonomy id's) with the login user.

So for example If I've added 'photoshop' to my skills and when I login the view should provide me other user who have tagged their profiles with taxonomy term 'Photoshop'.

Note: view of users having same taxonomy term as well as login user have.

Thanks

10
  • try filter by your skill field..
    – Abin
    Commented Aug 7, 2015 at 10:26
  • @Abin you mean a contextual filter?
    – Ozyy
    Commented Aug 7, 2015 at 10:30
  • @Abin I cant seem to make it work .. Can you please explain which filter I need to use
    – Ozyy
    Commented Aug 7, 2015 at 10:42
  • sry for late rply, your view is for users right, then use the contextual filter and pass skill value
    – Abin
    Commented Aug 7, 2015 at 10:45
  • Another approach is try an exposed filter for Skill Field
    – Abin
    Commented Aug 7, 2015 at 10:52

3 Answers 3

2

The right way to solve this is by writing a default argument handler. A patch to do this was started here: https://www.drupal.org/node/721390

A "shortcut" to doing this would be to use the PHP Code default argument handler and plug it in directly. This is not generally recommended; it would be much better to put the code in a custom default argument handler so you should Google around for how to set one of those up as that's a bit beyond the scope of this question. But here are the steps for using the PHP Code approach and you can use the same logic for a default argument handler:

  1. Create a view listing users
  2. Add a contextual filter to filter on the user skills field
  3. In the contextual filter option, for "When the filter is not in the URL" choose "Provide a default value" and select "PHP Code" from the list.
  4. Assuming your field is named "field_skills", enter the following:

PHP code:

global $user;
$account = user_load($user->uid);
$terms = array();
if (!empty($account->field_skills['und'])) {
  foreach ($account->field_skills['und'] as $value) {
    $terms[] = $value['tid'];
  }
}
return implode('+', $terms);
  1. Down towards the bottom of that form there's a "more" link. Be sure to open that section of the form and select "Allow multiple values".

At this point, you should have the list that you want with one caveat: the currently logged-in user will show up in this list. You probably don't want this. To prevent that from happening add another contextual filter that excludes the current user from the list:

  1. Add a contextual filter on the User:Uid value
  2. Choose "Provide default value" for "When the filter is not in the URL" and, out of that list, choose "User ID from logged in user".
  3. Under the "more" link at the bottom, choose the "Exclude" option.
3
  • You're a life saver and it's all working. Thank you :)
    – Ozyy
    Commented Aug 10, 2015 at 15:16
  • is there any way I can tell how many skills are in common between two users. Like Person 'X' follow Person 'Y' as person 'y' has 2 common skills with you. thanks
    – Ozyy
    Commented Aug 10, 2015 at 15:20
  • I don't think PHP code or filter is needed for this to work. It can work on relationship & contextual filter.
    – RajeevK
    Commented Aug 10, 2015 at 18:56
0

This is so simple to create views of users having same taxonomy terms.

  1. Add a new views of type user.
  2. Under Filter Criteria add your term field ie skill field and select a term(photoshop) according to which you want to filter. Save the views and cheers.
8
  • thanks for your quick reply but my requirement is slightly different. I Want this view to look into 'logged in user' and match his/her skills (taxonomy) with other users therefore hard coded filter criteria wont work.
    – Ozyy
    Commented Aug 7, 2015 at 15:30
  • @Ozyy - You need to update your question accordingly..
    – RajeevK
    Commented Aug 7, 2015 at 21:21
  • @RajeevK - What I'm looking for is a view which looks looks into logged-in user and present a list of other user who share the same skills (taxonomy) as logged in user. keeping in mind that every user has as 'Term reference' field attached to their profile which they can edit. Does it make any sense?
    – Ozyy
    Commented Aug 8, 2015 at 8:19
  • @OzyyI got your point YES. But please edit your original question, thats what I am asking.
    – RajeevK
    Commented Aug 8, 2015 at 11:39
  • @RajeevK, I think my question states what I'm looking for. If you got my point than do you've a fix for my issue. Your help would be much appreciated.Thanks
    – Ozyy
    Commented Aug 10, 2015 at 11:22
0

This is how it should be done -

  • Create a views block of users.
  • Add a relationship for your required taxonomy vocab (in your case it's skills)
  • Add a contextual filter of User:uid, provide value from URL & add default argument as Userid of logged in user.
  • Place block on relevant page & check.

Note - I haven't done it myself or have similar exp. But logically, this should work.

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.