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.

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;
}?>
share|improve this question
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 '13 at 1:09
    
Thank you for your advice. –  Genxer Jan 14 '13 at 1:11

1 Answer 1

up vote 0 down vote accepted

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.

share|improve this answer
    
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 '13 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 '13 at 1:23

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.