My code doing this, listing which author have posted in the current category. But get_avatar function not correct working. Im Using Simple Local Avatar Plugin. It is working author.php don't have any problem. But when i use it my this code, it is listing same and wrong author picture(My latest author picture. You can look this picture)

My Code:

<?php if (is_category()) {
$current_category = single_cat_title(“”, false);
$author_array = array();
$args = array(
'numberposts' => -1,
'category_name' => $current_category,
'orderby' => 'author',
'order' => 'ASC'
$cat_posts = get_posts($args);
foreach ($cat_posts as $cat_post) :
if (!in_array($cat_post->post_author,$author_array)) {
$author_array[] = $cat_post->post_author;
foreach ($author_array as $author) :
$auth = get_userdata($author)->display_name;
$autid= get_userdata($author)->ID;
echo get_avatar( get_the_author_email(), '32' );
echo "<a href='?author=";
echo $autid;
echo "'>";
echo $auth;
echo "</a>";
echo "<br />";
  • 1
    Off-topic: you don't need a closing PHP tag ?>, if you are going to open it in the very next line <?php without any Html in between (check this Q&A). Also, indent the code so it is easier to read (for you and for the ones that may be willing to help).
    – brasofilo
    Jan 14, 2013 at 1:09

1 Answer 1


You pull the author ID here:

$autid= get_userdata($author)->ID;

So why aren't you using it to get the avatar on the very next line?

echo get_avatar( get_the_author_email(), '32' );

get_avatar will accept the ID as a parameter. Try this instead:

echo get_avatar( $autid, '32' );

get_the-author_email is deprecated anyway so even if it worked you shouldn't be using it.

  • Yes this is true im used this echo get_avatar( get_the_author_email(), '32' ); so many wrong and im a little confused..It is working perfectly now.Thank you for answer.
    – Genxer
    Jan 14, 2013 at 1:22
  • That code should work (until the deprecated function is removed) under the right circumstances, but you already have the ID so the function call would be pointless anyway.
    – s_ha_dum
    Jan 14, 2013 at 1:23

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.