Skip Navigation

[Resolved] I need to get the Post Author Role

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

Problem:

I need to show some content to the user, using a conditional logic by Post Author Role

Solution:

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

Relevant Documentation:

This support ticket is created 4 years, 8 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
- 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 9: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/Hong_Kong (GMT+08:00)

This topic contains 5 replies, has 2 voices.

Last updated by francescoG-3 4 years, 8 months ago.

Assisted by: Luo Yang.

Author
Posts
#1320473

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? hidden link

#1320745

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

#1321241

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?

#1321255

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"

#1321727

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:
hidden link

the url parameter "role" value "autore_abbonato" is the slug of custom user role

#1322539

My issue is resolved now. Thank you!

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