0

I have some posts, each post have different authors(users).
I save each author image avatar in user_meta table.
Now i want show each author avatar in self posts. i get user_id with wp_get_current_user() function. but it work when user is logged in, i want when user not logged in get user id and show user avatar

Here my code

first way show user post avatar to all post not work $current_user = $post->post_author;

  <?php if (!empty(get_user_meta($current_user, 'user_avatar', true))): ?>
                        <img src="<?php echo get_user_meta($current_user, 'user_avatar', true); ?>" alt="some text">

Second way work, but whene user is logged in

$current_user = wp_get_currebt_user();

  <?php if (!empty(get_user_meta($current_user->ID, 'user_avatar', true))): ?>
                        <img src="<?php echo get_user_meta($current_user->ID, 'user_avatar', true); ?>" alt="some text">
0

To show author avatar per post inside loop you need to modify a little:

$current_post_author_id = get_the_author_meta( 'ID' );
<?php if (!empty(get_user_meta($current_post_author_id, 'user_avatar', true))): ?>
<img src="<?php echo get_user_meta($current_post_author_id, 'user_avatar', true); ?>" alt="some text">

Try, if it works for you.

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.