Skip to main content
edited tags
Link
GiorgosK
  • 8.5k
  • 1
  • 42
  • 55
Source Link

Show Targeted Content Based on Content Field and User Roles

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!