0

I am using:

echo get_avatar(get_the_author_id(), 30);

Which works, however i am getting this notice to use:

echo get_avatar(get_the_author_meta(), 30);

Which doesn't display the authors Gravatar image, just the Gravatar default image.

**Notice:** get_the_author_ID is deprecated since version 2.8! Use get_the_author_meta('ID') instead. in C:\Users\Administrator\Desktop\www.wpsites.dev\wp-includes\functions.php on line 2908

So my question is, what should i use to display the posts author Gravatar?

4

Notice: get_the_author_ID is deprecated since version 2.8! Use get_the_author_meta('ID') instead. in C:\Users\Administrator\Desktop\www.wpsites.dev\wp-includes\functions.php on line 2908

You aren't using get_the_author_meta('ID'); as instructed by the Notice. You are just using get_the_author_meta(). The latter returns an empty string when I try it.

Reference

http://codex.wordpress.org/Function_Reference/get_the_author_meta

  • I don't want to add the i.d because different posts have different authors which is why i added the email id which works perfectly. get_the_author_meta('ID') doesn't work without adding the i.d or email. – Brad Dalton Mar 22 '14 at 15:21
  • 1
    @BradDalton : That is a hard-coded string, not a variable. You are asking for the ID of the author (as opposed to the "nickname" for example) not supplying it. – s_ha_dum Mar 22 '14 at 15:24
2

When looking at the source of get_avatar(), you can see that it takes either ID or email as 1st argument:

get_avatar( $id_or_email, $size = '96', $default = '', $alt = false );

The source of get_the_author_meta() shows that it will return data for the following fields:

'login', 'pass', 'nicename', 'email', 'url', 'registered', 'activation_key', 'status'

As addition to @s_ha_dum answer, you can as well use email user meta data as 1st argument for get_avatar():

echo get_avatar( get_the_author_meta( 'email' ), 30 );

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.