Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9009337
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T02:09:51+00:00 2026-06-16T02:09:51+00:00

this code will display the newest post from a certain category. the post will

  • 0

this code will display the newest post from a certain category. the post will only display
excerpt, beside it is a user avatar.

note: im using plugin called local avatar

    //display newest post// 
    <?php
       global $post;
       $args = array( 'numberposts' => 1, 'category' => 1 );
       $myposts = get_posts( $args );
       foreach( $myposts as $post ):setup_postdata($post); ?>

       //gets user avatar and excerpt//
       <?php echo get_avatar( get_the_author_meta( 'user_email' )); ?>
       <a href="<?php the_permalink(); ?>"><?php echo get_excerpt(100); ?>... </a>

     <?php endforeach; ?>

according to wordpress, if i want to display the user avatar i should include the following inside the loop <?php echo get_avatar( $id_or_email, $size = '50'); ?>
this code displays the default avatar only.

so i used this, which was taken from the default wordpress template
<?php echo get_avatar( get_the_author_meta( 'user_email' )); ?> both locally uploaded avatar and gravatar works.

i just want clarity as to why the latter works and not the one found in wordpress codex.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-16T02:09:53+00:00Added an answer on June 16, 2026 at 2:09 am

    They are both exactly the same function except one is a guideline taken from the WordPress documentation and one is in action.

    Let me explain:

    $id_or_email and $size = '50' are placeholders to show you what sort of paramaters the get_avatar() function takes. Because $id_or_email is not by default a declared variable in WordPress it has a value of undefined. So what you are really writing is:

    get_avatar(undefined, 50)

    get_avatar() requires either an user’s ID or email address as the first parameter for it to return their avatar. Because you supply it neither of these WordPress falls back onto the default avatar.

    Because get_the_author_meta( 'user_email' ) returns an email address you are successfully fulfilling the required paramaters of get_avatar(). The second paramater $size is optional and defaults to 96.

    See http://codex.wordpress.org/Function_Reference/get_avatar#Examples for more uses.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This code will display the selected value from the listbox. E.g. if I sellect
I'm using this code, from the nerddinner example. This method will display a list
from this code will show in original color how can i change it to
I have this code which will include template.php file from inside each of these
This code will display selected checkboxes Text in textbox as in the order i
I have this datatable, which will display the values from the database. private void
This code will get us all the properties of a class: Dim myPropertyInfo As
this code will not pass the query string to default3.aspx on Image Button ..
This code will output some blinks on divs when we do the mouse over.
I am unsure why this code will not work. When I click a button

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.