I can't get a conditional field group logic to work on a CRED form.
I have written this code:
[cred_show_group if="(USER(‘role’) eq ‘administrator’)" mode="fade-slide"]
Privacy
[cred_field field='privacy' force_type='taxonomy' output='bootstrap' display='select' single_select='true']
[/cred_show_group]
What I want to have happen is when the current logged-in user has role = administrator, then the field inside the group will show.
Hi Tim,
Thank you for waiting.
The "cred_show_group" shortcode is designed to work with conditions based on the data in the form's fields.
To conditionally include/exclude a field based on a user's role, you can use conditional display shortcode "wpv-conditional", instead.
( ref: https://toolset.com/documentation/user-guides/views/conditional-html-output-in-views/using-shortcodes-in-conditions/ )
Example:
[wpv-conditional if="( '[wpv-current-user info="role"]' eq 'administrator' )"]
[cred_field field='privacy' force_type='taxonomy' output='bootstrap' display='select' single_select='true']
[/wpv-conditional]
This will show the enclosed field, only when the current user's role is "administrator".
( ref: https://toolset.com/documentation/user-guides/views/views-shortcodes/#wpv-current-user )
I hope this helps and please let me know if you need any further assistance around this.
regards,
Waqar
This is great - thank you. However it does not appear to work with custom user roles I create through Toolset Access? I have created a role "Member".
Also, what if I wanted a condition that would display for a user if they were in x-role OR y-role? Appreciate your support. I've been able to build something quite amazing with Toolset; great success story for your plugin. Almost there!!
Hi Tim,
Thank you for waiting.
I've performed several tests on my website, but couldn't reproduce this issue of the conditional display not working for the custom user roles.
Have you tried to see the output of shortcode [wpv-current-user info="role"] directly, in the form's editor?
Please test this shortcode as it is, while logged in as a user with "Member" role and see what is returned.
( you'll probably see "member" )
After that, please make sure you're using that same output for the comparison in the conditional block:
Example:
[wpv-conditional if="( '[wpv-current-user info="role"]' eq 'member' )"]
[cred_field field='privacy' force_type='taxonomy' output='bootstrap' display='select' single_select='true']
[/wpv-conditional]
In case, the issue still persists, you're welcome to share temporary admin login details, for the website so that I can see how everything is set up.
Please also include the link to the page with this form and the login details for a user with the "Member" role that you're testing this with.
Note: Your next reply will be private and please make a complete backup copy, before sharing the access details.
As for your question about combining conditions to check for more than one role, yes that is possible too.
( ref: https://toolset.com/documentation/user-guides/views/conditional-html-output-in-views/nesting-and-combining-conditions/ )
Suppose you'd like to show a field only to "Administrator" or "Member" roles. The combined conditional block will look like this:
[wpv-conditional if="( '[wpv-current-user info="role"]' eq 'administrator' ) OR ( '[wpv-current-user info="role"]' eq 'member' )"]
[cred_field field='privacy' force_type='taxonomy' output='bootstrap' display='select' single_select='true']
[/wpv-conditional]
regards,
Waqar
My issue is resolved now. Thank you!