Welcome to the Question2Answer Q&A. There's also a demo if you just want to try it out.
+5 votes
in Q2A Core by
Once WordPress integration has been enabled, is there any simple way to display users' WordPress avatar on question posts and answer posts, or do we need to write a plugin to do so?

3 Answers

+1 vote

I had some trouble with this as well... the key is in finding the userid.  It's in $post['raw']['userid'], not $post['userid']!

So, using Buddypress, I add the function to my theme:

        function post_avatar($post, $class, $prefix=null)
            if (isset($prefix))
            $id = $post['raw']['userid'];
            $user_info = get_userdata($id);
            $email = $user_info->user_email;
            $avatar = bp_core_fetch_avatar( array( 'item_id' => $id, 'width' => 50, 'height' => 50, 'email' => $email ) );
            $this->output('<SPAN CLASS="'.$class.'-avatar">', $avatar, '</SPAN>');

In plain Wordpress, I guess you would use the get_avatar() function:


Hi, Noah, could you please explain  in a little details exactly on which file what code I should put in to display avatar on a wordpress integration.
0 votes
This has been fixed for version 1.5.3 of Q2A, which will display WordPress avatars on posts.
Wordpress avatars still not displaying in /users list page or user profile page. Why?
Same issue here. I use a Facebook login plugin on Wordpress and thought it may be the reason but not able to figure out why the avatar shows from WP correctly in Q&A pages and lists but not in user profile pages or top header bar?
+1 vote

This is what you do to show BuddyPress avatars in Q2A

1) Install the BuddyPress integration plugin by NoahY - this should take care of avatars in posts

2) In qa-external-wp-users.php under line 160 replace 

return qa_get_gravatar_html($qa_cache_wp_user_emails[$userid], $size);


if (isset($qa_cache_wp_user_emails[$userid]))
$user_info = get_userdata($userid);
$email = $user_info->user_email;
$avatar = bp_core_fetch_avatar( array( 'item_id' => $userid, 'width' => $size, 'height' => $size, 'email' => $email ) );
return $avatar;