0

I'm working on a plugin for showing users via shortcode by their role (in this site's case - authors). I'm getting a list of user objects using a WP_User_Query statement, then creating the output for each user like this:

foreach ( $users as $user ) { ?>

            <div class="sap_author_box">

                <div class="sap_author_pic"><?php get_avatar( $user->user_email, 150 ); ?></div>
                <div class="sap_author_name"><?php
                    echo '<a href="http://curbcollege.org/happytogethertour/author/' . $user->user_login . '">' . $user->display_name . '</a> <span class="smallertext">( ' . $user->age . ' ) - ' . $user->classification . ' from ' . $user->hometown . '</span><br />';
                    echo '<span class="smallertext">Major: ' . $user->major;
                    echo ( empty( $user->minor ) ? '</span>' :  ', Minor: ' . $user->minor . '</span>' ); ?>
                </div>
                <div class="sap_author_bio"><?php echo $user->user_description; ?></div>

            </div>

        <?php } // End of $users foreach

All the data from the user's profile comes out just fine, except the avatar. I've tried using $user->ID instead of email, but that doesn't work either. I know both the email and ID are called correctly because I can echo them onto the page and see them, so it's not that the data isn't getting to the get_avatar function. What am I doing wrong with get_avatar? I know some of the authors have avatars because I can see them on the Users list, but not on the output page. Ideas?

0

You forgot to echo it:

<?php echo get_avatar( $user->user_email, 150 ); ?>
  • Good grief. The simple things... :) I've looked at a bunch of tutorials on using get_avatar and didn't notice the echo statement on any of them. Thanks Eugene! – Slushman Jun 8 '12 at 15:22

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.