Show users any content that matches any taxonomy term in views

Our use case seemed pretty straightforward.  When users register on the site they select terms from a taxonomy list based on a field in their profile2 profile.  As content is added to the site the same taxonomy is used to categorize content.  We wanted a view that would let users see any content that matched any of their taxonomy term selections.

I’m on the drupal4lib mailing list and want to thank all those who responded, specifically Kelly Lucas aka krlucas who is quoted below

Start with a base View that shows Users (not Content).
1) Set a Contextual Filter for User ID, provide a default value and set it the
logged-in User’s ID
2) Create a relationship from the user to the user’s profile
3) Create a relationship from the field containing the select terms on the
user/user profile to the taxonomy terms
4) Create a relationship from the taxonomy terms to the nodes that have that
taxonomy term.

You should now be able to add the relevant node fields to the View.

walkthrough of a view

walkthrough of a view

using the query settings "distinct" to limit the values instead of one per term

using the query settings "distinct" to limit the values instead of one per term

whatcha get from all these relationships

whatcha get from all these relationships

What didn’t work: So while this seemed incredibly straightforward getting this many-to-many relationship to work caused me endless grief.  I tried views global filter thinking that might be a good solution – according to their documentation any fields pulled from the profile are used to override the values.  Using the multiselect widget this simply failed all over the place – values didn’t save at all, weirdness reigned, and general misery ensued.*

Also in the “fail” category – making a view based on the content table and the taxonomy table.  Either of these might have worked with a few more relationships, however at this point I think we’re stocked up.

Thanks to all involved who helped on this – Cary Gordon, Brazos**, and of course Kelly Lucas

*fwiw we read the entire issue queue and documentation, however this statement really hurt Rik’s feelings.  Would someone please hug him down under?

**Brazos added another interesting option of using page manager to override the user page and pass variables along that way – I’m not experienced in this line of development to implement, but it seems interesting.

 

This entry was posted in Planet_Drupal and tagged , , , , , , , , , , . Bookmark the permalink.

7 Responses to Show users any content that matches any taxonomy term in views

  1. RdeBoer says:

    I tried “Views Global Filter” thinking that might be a good solution – according to their documentation any fields pulled from the profile are used to override the values. Using the “Multiselect widget” this simply failed all over the place – values didn’t save at all, weirdness reigned, and general misery ensued.

    Obviously I don’t like seeing words like “weirdness reigned” and “general misery” being used publicly in the context of my module, Views Global Filter, or that of fellow Drupal developers, the maintainers of the Multiselect module.

    Did you even ask for assistance from any of the maintainers of Views Global Filter or Multiselect before you publicly spat your bile? Did you log an issue? I don’t see one in the Views Global Filter queue.
    Both modules have a respectable number of installs, so for many people these modules clearly DO work.
    Moreover the developers will have easily spent hundreds of hours so that the community can enjoy these modules. For FREE.
    Have you ever thought that sometimes despite the best coding practices, due to some silly triviality, two modules that weren’t designed to work together in the first place sometimes indeed don’t play nice? And that this can often be fixed, again at no cost to you, if you’d just asked the maintainers or the community at large?

    As a Drupal developer, if feel offended and upset, and I believe many developers will feel the same.

    Next time spend a little more time on working on a solution than on being rash and rude on Planet Drupal.

    Rik de Boer
    author/maintainer of Views Global Filter and a few other modules

  2. Pingback: Drupal 7 short stack – Review from accsva.org presentation | Wordpress VS Drupal

  3. pmarx says:

    Hey so I’m trying to follow your lead here (and thanks I’ve been looking for something like this forever) but for some reason I’m not seeing the User: Uid option as a possibility for contextual filter. Any idea why that might be? Help would be greatly appreciated

  4. pmarx says:

    I have another question for you relating to this, if that’s ok — do you know if it’s doable to have the results sorted by greatest number of taxonomy matches? Or some custom metric? How would you go about approaching that?

  5. alibama says:

    sure man – you may need to turn on aggregation, apply a count to the taxonomy terms, and then add a sort field. http://drupal.stackexchange.com/questions/1342/views-and-node-count-for-taxonomy-terms should make sense of this