Get field_ id from BuddyPress profile fields in extended profile

I can get a profiles avatar and name by this code:

?php echo get_avatar(1); ?>

            <?php 
                $user_id = 1;
                $key = 'first_name';
                $single = true;
                $user_first = get_user_meta( $user_id, $key, $single ); 
                echo '<span>' . '' . $user_first . '</span>'; 
            ?>

But then I also have BuddyPress installed and trying to get the new fields that I created there. I identified the id on one of the field to fields_2

Read More

This is what I have written that don’t work:

<?php 
            $user_id = 1;
            $key = 'field_2';
            $single = true;
            $user_field = get_user_meta( $user_id, $key, $single ); 
            echo '<span>' . '' . $user_field . '</span>'; 
        ?>

How can I get this field_2 from the extended BuddyPress field?

Related posts

Leave a Reply

1 comment

  1. Check your database if it actually has “field_2”, your code should work fine. but you can also try using it inside the bp user loop and also replace get_user_meta with bp_get_user_meta. It works better with some buddy press plugins.

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