0

I'm looking for a way to retrieve all authors with their avatar.

I know there is a way to get an authors avatar but I want to get all avatars of all the authors :)

echo get_avatar(get_the_author_meta('ID'), '160');

I tried to combine this command with wp_list_authors() but didn't find a way.

How can I retrieve a list of all authors with their avatars?

Thank you!

3
  • Keep in mind that authors are just users that have posts, behind the scenes wp_list_authors just uses the user API functions, and so can you, get_the_author_meta is just a wrapper around get_user_meta( $post->post_author, 'ID'... – Tom J Nowell Oct 18 '20 at 18:17
  • Use wp_list_authors() and put them into an array then loop through the array using get_avatar() for each. – Tony Djukic Oct 18 '20 at 19:24
  • I don't believe wp_list_authors is the solution, that function returns a HTML/plaintext string rather than an array of users – Tom J Nowell Oct 18 '20 at 21:45
0

I would loop through an array with the authors and then get their avatar and save them in a different array. You can use get_users() to get the users and you already know how to get their avatar.

You can get users using get_users() by giving it an array with arguments to specify what you need. You can see the available arguments to pass in the documentation for get_users(). This will return an array with users to loop through.

6
  • Can you explain retrieving a list of authors? The OP mentioned wp_list_authors but hadn't figured out how to use it – Tom J Nowell Oct 18 '20 at 21:39
  • You should read the docs on this function, they are pretty clear. developer.wordpress.org/reference/functions/wp_list_authors If you still have questions after scanning this, I'll be happy to answer them. – Tom Oct 18 '20 at 21:40
  • 1
    Oh I know how to use it :) But try to make your answers self contained, the OP may be missing a vital piece of information that's obvious to all of us, or be new too PHP. There's no no need to write out a copy paste solution though – Tom J Nowell Oct 18 '20 at 21:42
  • 1
    btw looking at the documentation suggests that wp_list_authors returns a string, not an array of users that can be looped with. Perhaps get_users may prove more useful – Tom J Nowell Oct 18 '20 at 21:44
  • 1
    @TomJNowell Good catch, hadn't noticed that. Updated the answer, thanks! – Tom Oct 18 '20 at 21:49

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy