Skip Navigation

[Resolved] How to display content conditionally based on different roles

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

Problem:
How to display content conditionally based on different roles

Solution:
Either you can use [toolset_access] or [wpv-conditional] shortcode to display conditional content.

You can find the proposed solution, in this case, with the following reply:
=> https://toolset.com/forums/topic/the-single-post-template-file/#post-1115675

Relevant Documentation:
https://toolset.com/documentation/views-shortcodes/#wpv-conditional
https://toolset.com/documentation/user-guides/conditional-html-output-in-views/

This support ticket is created 6 years, 3 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.

Sun Mon Tue Wed Thu Fri Sat
- 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 -
- 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 -

Supporter timezone: Asia/Kolkata (GMT+05:30)

Tagged: 

This topic contains 4 replies, has 2 voices.

Last updated by michaelW-27 6 years, 3 months ago.

Assisted by: Minesh.

Author
Posts
#1115225

I am wanting to make my Archive pages with limited post info viewable to everyone but the subsequent single post template file un-viewable to unregistered users- showing 2 x register here buttons instead of the content leading to their relevant registration form.

nothing else has been initiated on the site yet, I am just trying to map the whole thing down on paper 1st

The site is on a subdomain at present hidden link

#1115578

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

Hello. Thank you for contacting the Toolset support.

Well - sorry, but I did not get you well. I understand you want to show/hide some content with specific user role but could you please share a detailed information with text case example that will help me to guide you in the right direction.

#1115659
toolset.jpg

PLEASE SEE ATTACHED IMAGE TO CORRELATE WITH FOLLOWING TEXT.
I am creating a Venues and Artists website for registered users to view Registered artists and Registered Venues.
On the Archive page of all the different bands and venues I wish to show only info in the GREEN BOX, when unregistered viewer clicks on item they are directed to a registration form. For Registered Users when they click on item I wish to show only the content in the Red box on the single template file with an option to book VENUE or ARTIST - once a booking and deposit is paid the content in the BLUE BOX is available.

#1115675

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

Ok - I understood.

The first option - if you have installed Toolset Access plugin:
- you can use [toolset_access] shortcode.
For example:

[toolset_access role="customer" operator="allow"]
    display content for customer role
[/toolset_access]

 
[toolset_access role="dealer" operator="allow"]
    display content for dealer role
[/toolset_access]

[toolset_access role="author" operator="deny"]
This content will not be accessible by author role
[/toolset_access]

Second option:
- You can use View's [wpv-current-user] shortcode to get current logged in user information:
More info:
https://toolset.com/documentation/views-shortcodes/#wpv-current-user

Now, if you want to get current user role, you should use following code:

[wpv-current-user info="role"]

As you want to display custom fields based on a specific role, you can use [wpv-confitional] shortcode.

For example - to check 'customer" role:

[wpv–conditional if="( '[wpv-current-user info='role']' eq 'customer' )"]
  
Display your custom fields for administrator role
  
[/wpv–conditional]

More info:
https://toolset.com/documentation/views-shortcodes/#wpv-conditional
https://toolset.com/documentation/user-guides/conditional-html-output-in-views/

I hope this will help you to resolve your issue. Please feel free to get in touch with me with your queries if any.

#1115748

My issue is resolved now. Thank you!