Skip Navigation

[Resolved] wpv-user role

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.

This topic contains 2 replies, has 2 voices.

Last updated by victorT 7 years, 5 months ago.

Assigned support staff: Luo Yang.

Author
Posts
#227776

I need to show the wpv-user "role".

I have tried [wpv-current-user info="role"] but this is giving me my current user role, and I need to show the author's role, not mine.

How can I achieve this?

#227833

Luo Yang
Supporter

Languages: English (English ) Chinese (Simplified) (简体中文 )

Timezone: Asia/Hong_Kong (GMT+08:00)

Hi victorT,

According to wordpress document,
http://codex.wordpress.org/Function_Reference/the_author_meta
There isn't user role meta for post meta, so Views shortcode wpv-post-author won't works in your case,
I suggest you try create another shortcode for it, like this:
1) add codes in your theme/functions.php:

add_shortcode('get_user_role', 'get_user_role_func');
function get_user_role_func($atts, $content){
	$atts = shortcode_atts( array(
 	      'user_id' => 0,
    ), $atts );
	$user = new WP_User( $atts['user_id'] );
	$arr = array();
	if ( !empty( $user->roles ) && is_array( $user->roles ) ) {
		foreach ( $user->roles as $role )
			$arr[] = $role;
	}
	$res = implode(', ', $arr);
	return $res;
}

2) use below shortcodes in your content:
[get_user_role user_id='[wpv-post-author format="meta" meta="ID"]']

Then you can get current post author roles, like this:
administrator, role2, role3

#227858

It worked like a charm.

Thanks Luoy!