1

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?

1 Answer 1

0

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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