Skip Navigation

[Resolved] Show content dynamically based on author’s role

This thread is resolved. Here is a description of the problem and solution.

Problem: I would like to show content dynamically based on the author's role and the current visitor's role. If they are in the same role, the content should be displayed.

Solution: Use Access post groups to display content conditionally based on User role.

Relevant Documentation:
https://toolset.com/documentation/user-guides/limiting-read-access-specific-content/

This support ticket is created 6 years, 2 months ago. There's a good chance that you are reading advice that it now obsolete.

This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.

No supporters are available to work today on Toolset forum. Feel free to create tickets and we will handle it as soon as we are online. Thank you for your understanding.

Sun Mon Tue Wed Thu Fri Sat
8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 - -
13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 - -

Supporter timezone: America/New_York (GMT-04:00)

Author
Posts
#1097422

I'm trying to create a site where the posts are default hidden, but shown to the users that belong to the same role as the post author. In other words the site has multiple authors in different "groups" (role) and they should be able read each others posts.

I know how to show the post only to the logged in author dynamically, but how to do the same based on role of the logged in user?

If this is not possible, I should create a view for every role. This seems a bit clumsy when there are lots of roles/groups. Another way would be to share the user account, but that of course is not a good solution.

#1097922

Hi, have you looked at Access Post Groups? Depending on your site's workflow, they may be useful.
https://toolset.com/documentation/user-guides/limiting-read-access-specific-content/
Apply a post group to any post, and then you can create Access restrictions for specific User roles, based on those post groups. One limitation is that it's not currently possible to set a post group programmatically or when a Form is submitted. The only way to set it is in wp-admin when you create or edit a post. So if your site's content is driven by Forms, this approach would require manual intervention in each post.

A more basic approach uses conditional HTML to test the current User's role against the author's User role. This approach does not prevent Users from accessing URLs of content in other groups, but you can use it to hide the content on those pages. I can give you more information about that if you're interested.

#1098685

Hi Christian, thank you! I have missed the access groups - I must get into that, it probably does what I need. Thanks again!