0

I have a taxonomy term that gets assigned to a content type via entity reference, and the Drupal user, via Profile 2.

I want to add a filter to a content view that matches the 2 up, so if you filled in your user profile saying you only interested in x, have a view that only show content that was assigned with the same term.

I have tried adding author, profile2, taxonomy term relationships etc without any luck. Any pointers would be greatly appreciated.

1

I managed to solve this: The key is to start with an User View.

Add Relationship -> User: Profile
Pick the profile where the taxonomy was assigned.

Add Relationship -> Content: Taxonomy terms on node
Pick your vocabulary.

Add Relationship -> User: Content authored
Add Contextual filter -> Content: Has taxonomy term ID

Choose PHP as a Provide default value option:

global $user;
$profiles = profile2_load_by_user($user);
    foreach ($profiles as $profile) {
      if ($items = field_get_items('profile2', $profile, 'field_your_interests')) {
        break;
      }
    }
$tids = array();
foreach ($items as $item) {
  $tids[] = $item['tid'];
}
return implode('+', $tids);

Then add the fields and additional filters as needed.

Resources:
http://blog.ampli.fi/filtering-a-drupal-7-view-based-on-multiple-user-profile-fields/
https://www.drupal.org/node/1111722#comment-4315620
Drupal terms and arrays - thanks Aaron!

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.