WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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>'; 
share|improve this question

closed as off-topic by toscho Aug 2 '14 at 20:54

This question appears to be off-topic. The users who voted to close gave this specific reason:

If this question can be reworded to fit the rules in the help center, please edit the question.

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
up vote 1 down vote accepted

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 );
share|improve this answer

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 ); 
share|improve this answer

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