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.

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?

share|improve this question

2 Answers 2

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

share|improve this answer
    
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 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 at 15:24

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 );
share|improve this answer
    
Impressive. Thanks for the edit Kaiser. –  Brad Dalton Mar 23 at 21:19

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.