Skip Navigation

[Resolved] Conditional Display (User Role) Behaving Oddly

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

Problem:
How is the correct syntax to check the current user role with a HTML condition?

Solution:
Examples:

[wpv-conditional if="( '[wpv-current-user info="role"]' eq 'guest' )"]I AM A guest[/wpv-conditional]
[wpv-conditional if="( '[wpv-current-user info="role"]' eq 'administrator' )"]I AM A administrator[/wpv-conditional]
[wpv-conditional if="( '[wpv-current-user info="role"]' eq 'contributor' )"]I AM A contributor[/wpv-conditional]

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

100% of people find this useful.

This support ticket is created 7 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
- - 14:00 – 20:00 14:00 – 20:00 14:00 – 20:00 14:00 – 20:00 14:00 – 20:00
- - - - - - -

Supporter timezone: Asia/Ho_Chi_Minh (GMT+07:00)

This topic contains 2 replies, has 2 voices.

Last updated by julieP 7 years, 2 months ago.

Assisted by: Beda.

Author
Posts
#494114

I have put these conditional statements into a text widget to use in my header:-

[wpv-conditional if="( '[wpv-current-user info='role']' eq 'guest' )"]I AM A GUEST[/wpv-conditional]
[wpv–conditional if="( '[wpv-current-user info='role']' eq 'contributor' )"]I AM A CONTRIBUTOR[/wpv-conditional]
[wpv-conditional if="( '[wpv-current-user info='role']' eq 'administrator' )"]I AM AN ADMINISTRATOR[/wpv-conditional]

As a guest, I see this:-

[wpv–conditional if="( '' eq 'contributor' )"]I AM A CONTRIBUTOR[/wpv-conditional]

As a contributor, I see this:-

[wpv–conditional if="( 'contributor' eq 'contributor' )"]I AM A CONTRIBUTOR[/wpv-conditional]

As administrator, I see this:-

[wpv–conditional if="( 'administrator' eq 'contributor' )"]I AM A CONTRIBUTOR[/wpv-conditional] I AM AN ADMINISTRATOR

I've also put the conditional statements on a page and am getting the same results.

Any ideas please?

(All my plugins are up to date)

#494318

Try this:

[wpv-conditional if="( '[wpv-current-user info="role"]' eq 'guest' )"]I AM A guest[/wpv-conditional]
[wpv-conditional if="( '[wpv-current-user info="role"]' eq 'administrator' )"]I AM A administrator[/wpv-conditional]
[wpv-conditional if="( '[wpv-current-user info="role"]' eq 'contributor' )"]I AM A contributor[/wpv-conditional]

This works fine on my install.

I created those conditions with the GUI for "Conditional Output", which makes sure the apostrophes and syntax is correct.

#494398

Thanks for that - I can see where mine was wrong

This ticket is now closed. If you're a WPML client and need related help, please open a new support ticket.