skip to Main Content

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

Answers


  1. 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" />
    
    Login or Signup to reply.
  2. 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 />';
        }
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search