Tell us what you are trying to do? I need to show some content to the user, using a conditional logic by Post Author Role
Is there any documentation that you are following? No
Is there a similar example that we can see? I don't know
What is the link to your site? lien caché
Hello,
There isn't such a built-in feature within Toolset, it needs custom codes, currently, you can try the solution in another similar thread:
https://toolset.com/forums/topic/conditional-output-if-wpv-post-author-is-a-administrator-or-other-roles/#post-1231330
Hi Luo,
thank you, but I think it not work.
So, I have created a Custom Role with Toolset Access and the name is "Autore abbonato".
I have created the Custom Code:
add_shortcode('ruolo-utente', 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;
});
And I have added this condition in a post
[wpv-conditional if="( '[ruolo-utente role="Autore abbonato"]' eq 1 )"]
Post di {!{wpv-post-author format='link'}!}
[/wpv-conditional]
[wpv-conditional if="( '[ruolo-utente role="Autore abbonato"]' ne 1 )"]
L'autore non è abbonato
[/wpv-conditional]
But it don't show me nothing...
Why?
Can you help me?
Sorry, I think it works now. I don't have added the shortcode into the third party shortcode section in the Front-end content Tab.
But, I don't know if it is right to write role="Autore abbonato" or role="autore-abbonato"
You can use the slug of custom user role: autore_abbonato
You can get above slug by this:
Dashboard-> Toolset-> Access control
find the custom user role "Autore abbonato", click link "View users", the URL is something like this:
lien caché
the url parameter "role" value "autore_abbonato" is the slug of custom user role
My issue is resolved now. Thank you!