i’m working on my first WP site and need to display an author’s role next to their post. Something like “Jimmy | Administrator”. Looking at the author metadata available: http://codex.wordpress.org/Function_Reference/the_author_meta doesn’t give me a way to access that. I’m sure there’s a quick easy way to do this and i just don’t know it!! Thanks!
Share
UPDATE: Place this in your functions.php file:
Then call this within your WordPress Loop. So:
…will print: ‘Jimmy | Administrator’
COMPLETE ANSWER: The User Object itself actually stores roles, and other kinds of useful information. If you want more of a general function to retrieve the role of any given user, simply pass in the ID of the user you want to target with this function:
And if you want to grab the author of a given post, call it like so:
RESPONSE TO LAST COMMENT:
If you need to grab data outside of the WordPress Loop (which I imagine you’re trying to do on an Archive and Author page), you can use the function from my Complete answer like so:
That will output the information you want in your “user | role” format.