WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I've been modifying a long abandoned plugin project that provides a Stackoverflow inspired badge system for Wordpress. I have upgraded some of its code so it functions with the new Wordpress version.

You can view the entire code here if you are interested: http://pastebin.com/kCWWLPL2

I want to add a code to the author.php page to list the author's awarded badges. So far, I have only managed to display the logged in user's badges with this working code:

$user_id = get_current_user_id();
if ($user_id != 0) {
  rhb_list_badges(array('user_ID' => $user_id));

I was told to use this code to display the author's badges:

$author = get_user_by( 'slug', get_query_var( 'author_name' ) ); 
if ($author->ID > 0) {
  rhb_list_badges(array('user_ID' => $author->ID));

But it does not return anything on the page. Why? What am I doing wrong here? How can I alter the working get_current_user_id code example so that it will display the author's badges and not the logged in user's one?

share|improve this question

Instead of using get_current_user_id() use

$current_view = get_queried_object();

The $current_view will have the same properties as get_current_user() if it is used in author.php. To get the User ID, just use

$current_view_id = $current_view->ID

Hope this help

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.