php - How to load User Meta? -


wordpress author.php not loading correct information user meta. it's loading whoever logged in blog , not displaying person links example:

http://www.website.com/author/username1 http://www.website.com/author/username2 

is displaying same despite been 2 different users. i've done asked, i'm still confused why loading user meta , not meta of username?

this author template:

<?php get_header(); ?>    <div class="author-name"> <?php echo get_the_author_meta('first_name'); ?> <?php echo get_the_author_meta('last_name'); ?>  <?php echo get_user_role('user_role'); ?> </div>  <div class="author-information"> username: <?php echo get_the_author('user_nicename'); ?> </div>  <?php get_footer(); ?>   

you must supply user id when using get_the_author_meta() different user 1 in loop or logged in.

assuming username1 , username2 actual usernames in users database table can username url using following snippet:

$username_from_url = basename( get_permalink() ); 

and then:

$user = get_user_by( 'login', $username_from_url ); 

now have full $user object id , everything.

edit: complete solution

user visits url following pattern /page/somename somename corresponds user´s user_nicename in database table users.

<?php     $username_from_url = basename( get_permalink() );     $user = get_user_by( 'slug', $username_from_url );      echo get_the_author_meta( 'first_name', $user->id );     echo get_the_author_meta( 'last_name', $user->id );      foreach ($user->roles $role) {         // can use get_role( $role ) more data on role         echo $role;     }      echo __( "username:" ) . " " . $user->user_nicename; ?> 

Comments

Popular posts from this blog

javascript - Bootstrap Popover: iOS Safari strange behaviour -

Magento/PHP - Get phones on all members in a customer group -

session - Logging Out Using PHP -