Skip Navigation

[Resolved] How to display user role in loop?

This support ticket is created 7 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 – 12:00 9:00 – 12:00 9:00 – 12:00 9:00 – 12:00 9:00 – 12:00 -
- 13:00 – 18:00 13:00 – 18:00 13:00 – 18:00 14:00 – 18:00 13:00 – 18:00 -

Supporter timezone: America/Jamaica (GMT-05:00)

Tagged: 

This topic contains 2 replies, has 2 voices.

Last updated by patrikS-2 7 years, 8 months ago.

Assisted by: Shane.

Author
Posts
#431750

I have a list of all users on my website and I want to display the user role for each of those users but I can't seem to find a way to do that within the Views-plugin.

#431887

Shane
Supporter

Languages: English (English )

Timezone: America/Jamaica (GMT-05:00)

Hi Patrik,

Thank you for contacting our support forum.

Unfortunately the only shortcode we have to handle, however with a bit of custom coding you can achieve it by doing this.

Add the following to your functions.php file.

// Add Shortcode
function getuser_role( $atts ) {

	// Attributes
	$atts = shortcode_atts(
		array(
			'user_id' => '',
		),
		$atts
	);

	$user_info = get_userdata($atts['user_id']);
	    
	      return implode(', ', $user_info->roles);
	   

}
add_shortcode( 'getuser_role', 'getuser_role' );

You can use the shortcode by doing this [getuser_role user_id='[wpv-user field="ID"]']

Please try this and let me know if this helps.
Thanks,
Shane

#432504

Thank you, Shane.

For some reason it didn't work at first, but I changed the functions name from getuser_role to get_usersrole and then it worked perfectly.

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