-1

I want to show a custom Avatar image field on the author page. The following code is working for me, but shows as can be guesses the field of the current user. It should show the avatar field of the specific author.

the_field('avatar', 'user_'. $user_ID);
?>
    
<img src="<?php the_field('avatar', 'user_'. $user_ID); ?>" width="50" height="50"> ```

2 Answers2

0

Need to grab the Author ID... You can use get_queried_object_id() for this on the author.php template like below:

<img src="<?php the_field('avatar', 'user_'. get_queried_object_id()); ?>" width="50" height="50" />
mikerojas
  • 2,238
  • 1
  • 4
  • 7
  • '$author_id = get_the_author_meta('ID'); $author_badge = get_field('avatar', 'user_'. $author_id ); ?> ' I tried this, but sadly it didn't work. I use woody snippets to show in on the Author Archive page. – jordyblanken Jan 15 '22 at 16:50
0

simply use get_users()

$siteUsers = get_users( array( 'role__in' => array( 'administrator', 'subscriber' ) ) ); // u can change
    foreach ( $siteUsers as $user ) {
        echo '<span>' . esc_html( $user->display_name ) . '</span><br />';
        echo '<img src="' . esc_attr( get_field('field_name', 'user_'.$user->ID) ) .'" alt="' . esc_attr( $user->display_name ) . '" /><br />';
    }
Mehde mohamad
  • 71
  • 1
  • 2