What is the proper way to display User Meta in the BP Loop using this line from codex?

 <?php get_user_meta($user_id, $key, $single);  ?>

I added that line to the profile loop and switched those values with ones from my DB and nothing happened. What am I doing wrong?

  $user_id = 9;
  $key = 'last_name';
  $single = true;
  $user_last = get_user_meta( $user_id, $key, $single ); 
  echo '<p>The '. $key . ' value for user id ' . $user_id . ' is: ' . $user_last . '</p>'; 
  • There is nothing wrong with the code you posted, do you mean you want a dynamic way to get the user id? maybe the displayed member id? – Ahmad M Feb 15 '13 at 13:15
  • No Ahmad. I wanted to retrieve something from the database. The guys in the chat have actually given me the answer – Androliyah Feb 15 '13 at 14:35

Inside the loop, you can get the currently iterated user id using bp_get_member_user_id().

Also, it's best practice to use bp_get_user_meta(), because it works better with certain kinds of BP plugins (multi-network, etc).


if ( bp_has_members() ) {
    while ( bp_members() ) {
        $user_last = bp_get_user_meta( bp_get_member_user_id(), 'last_name', true );

Silly me. I forgot to replace this line

$user_last = get_user_meta( $user_id, $key, $single ); 

with actual values

$user_last = get_user_meta( 1, nickname, true ); 

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