0

I have an author profile page where I'm displaying a user avatar and information about the author. On this same page, I'm also trying to include posts by other authors with their avatar displayed next to their post title. The problem I'm having is that get_avatar(get_the_author_meta('ID')) is only displaying the avatar of the current profile page author and not the author of the posts within the loop. So instead of the different author avatars, I have the avatar of the current author page repeated over and over.

Here is my code:

$args = array(
    'cat' => '55',
    'posts_per_page' => '3'
);

$Voices = new WP_Query($args);
    if ($Voices->have_posts() ) {
        while ($Voices->have_posts() ) {
            $Voices->the_post();
            echo get_avatar(get_the_author_meta('ID'), 150);
            echo '<a href="' . the_permalink() . '">' . the_title() . '</a>';  
            coauthors_posts_links();
        }
    }

wp_reset_postdata();  

1 Answer 1

2

Have you tried to specify the $userID parameter of get_the_author_meta(), like shown below:

echo get_avatar(get_the_author_meta( 'ID', $post->post_author ), 150);

This uses the post_author key from your secondary query, which has the ID as value, that said you should be able to shorten your code to:

echo get_avatar( $post->post_author, 150);
1

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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