Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

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:

<?php
$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:

<?php
$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

1 Answer 1

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

 
discard

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.