WordPress get_avatar function not correct working

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;
}
endforeach;
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 />";
endforeach;
}?>

Related posts

Leave a Reply

1 comment

  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.