I'm looking for a way to show specific targeted content based on a content type's field and user role.

For example, if user1 has a "Content Group 1" role, then the view should show content pieces with "field_content_grouping" == "Content Group 1". User2 having a "Content Group 2" role should only be able to see "Content Group 2" and so on. Both roles & field values are exactly the same.

I'm looking for the best way to properly execute this. I've seen people do similar things with pre-render for views or views query alter hooks. My general line of thinking is:

  1. Before rendering views get User roles: Loop and check roles against a specific field "field_content_grouping" - if there is a match, continue else unset node from view.

  2. Return full results (sans content pieces without a matching field & role).

What's the best way to accomplish something like this? Or am I completely on the wrong track all together? Any and all assistance is greatly appreciated, thanks!

1 Answer 1


You can make your content field a taxonomy term and you can accomplish this with a simple view without any custom coding.

If we assume

  • vocabulary Departments
  • user has field Departments
  • some users with department selected
  • token and views_argument_token installed

Add a content view

  • Add any relevant filters (content types, etc)
  • Add user relationship
  • Add contextual filter Has taxonomy term id
    • Provide default value > token and fill in the current user's selected term id which in this case is [current-user:field_department:target_id]
    • use Browse available tokens to find the relevant token

Here is a screenshot of a working view

enter image description here

  • sorry I forgot to mention the module dependencies, updated the answer
    – GiorgosK
    Mar 26, 2019 at 15:28
  • Thank you so much! This was very helpful! :)
    – Daniel
    Mar 26, 2019 at 16:51

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.