Hi Luo,
You have been helping me on this topic earlier and this is the thread:
https://toolset.com/forums/topic/conditional-output-if-wpv-post-author-is-a-administrator/
I have tried what you tell me to do and it's work find for the administrator role, but doesn't work for any other role that I created.
I'm creating a membership website with three membership options. Free, Silver and Gold. Each membership is attached to a role in WordPress. I have created those roles with ToolSet Access.
Now I want to show the member profil information depending if has one of these roles. This is an example :
[wpv-conditional if="( '[user_role_func]' eq 'silver_membership' ) OR ( '[user_role_func]' eq 'gold_membership' )"]
<div class="bio">Bio : [types field='bio'][/types]</div>
[/wpv-conditional]
So that means that if the actual author of this profile has a silver membership OR a gold membership, you can show that information to the public. That means that this information won't be showed on all FREE membership profile.
Actually, that doesn't work. This condition only work with [user_role_func]' eq 'administrator' ).
Is there a way to make it works for all roles that I have created?
I'm not sure what I'm doing wrong here.
Thanks for your help!
Hello,
Thanks for the details, I can login into your website.
Please point out the URLs of your website:
- Where I can edit your custom PHP codes
- Where I can test the shortcodes in front-end
Thanks
Hi Luo,
- Where I can edit your custom PHP codes
You can go on the left in Settings -- PHP inserter. You will find the function to get the author role there (function get_author_role())
- Where I can test the shortcodes in front-end
I'm using this shortcodes in my ToolSet Views "Listing View (single)". But you will need to create your own listing first by going into "My account" at the top and looking for "listing" on the left side. You fill the fields and you will be able to see your listing in "Find a practitioner" in the top menu. Or you can also just look at my listing "OK Web Design". I have put myself all the roles (admin, FREE membership, SILVER membership and GOLD membership). You can also attribute yourself other roles to try the function.
Thank you very much for your help!
Thanks for the details, WordPress can setup only one role for each user by default, but you are using another plugin "multiple-roles", each user can have multiple user roles in your website.
So the custom shortcode [user_role_func] won't work as expected in your case.
I suggest you create another shortcode [author-has-role] for it, for example:
1) Add below PHP codes into your theme file "functions.php":
add_shortcode('author-has-role', function($atts, $content){
$atts = shortcode_atts( array(
'role' => '',
), $atts);
global $authordata;
$author_roles = $authordata->roles;
$res = 0;
if ( $atts['role'] && in_array($atts['role'], $author_roles) ){
$res = 1;
}
return $res;
});
2) Dashboard-> Toolset-> Settings-> Front-end Content
in section "Third-party shortcode arguments", add the new shortcode name: author-has-role
3) Use above shortcode like this:
[wpv-conditional if="( '[author-has-role role="administrator"]' eq 1 ) OR ( '[author-has-role role="subscriber"]' eq 1 )"]
the author has one of those roles: administrator, subscriber
[/wpv-conditional]
This is perfect! Exactly what I needed! Works like a charm!
My issue is resolved now. Thank you!