Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

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?

<?php 
  $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
    
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 –  Aliyah Feb 15 '13 at 14:35
add comment

2 Answers

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).

Thus:

if ( bp_has_members() ) {
    while ( bp_members() ) {
        bp_the_member();
        $user_last = bp_get_user_meta( bp_get_member_user_id(), 'last_name', true );
    }
}
share|improve this answer
add comment

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
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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