Skip to:
Content
Pages
Categories
Search
Top
Bottom

How to retrieve usermeta data on members page ?

  • Avatar of valuser
    valuser
    Participant

    @valuser

    I have added a signup field like this:

    /* Add sign-up field to BuddyPress sign-up array */
    `function newbp_custom_user_signup_field( $usermeta ) {
    $usermeta = $_POST;

    return $usermeta;
    }
    add_filter( ‘bp_signup_usermeta’, ‘newbp_custom_user_signup_field’ );`

    /* Add field_name from sign-up to usermeta on activation */
    `function newbp_user_activate_field( $signup ) {

    update_usermeta( $signup, ‘newfield’, $signup );

    return $signup;
    }
    add_filter( ‘bp_core_activate_account’, ‘newbp_user_activate_field’ );`

    Have tried the following function

    `function getnewfield() {
    $data = get_user_meta($user_id, $newfield);
    if ( $data )
    echo “New Field Label: $data “;
    }
    add_action( ‘bp_directory_members_item’, ‘getnewfield’ );`

    But it has not retrieved the data. ?


    > the data is in the wp_usermeta database for each user_id

    Any input appreciated.

    (why usermeta ? Am trying out multi-networks and profile data appears to be network specific whereas usermeta data attaches to user across entire installation. ie. a user can have different profile info in different networks but his/her usermeta data is universal. I would like some user info to be universal! )

    wp 3.4.1,bp 1.6.1, multi-site, bp-multi-networks, networks+

Viewing 3 replies - 1 through 3 (of 3 total)
  • Avatar of shanebp
    shanebp
    Moderator

    @shanebp

    In function getnewfield() you need to give values to $user_id and $newfield.
    Otherwise, they are empty.

    But for this, I wouldn’t use the do_action.
    It’s a template file, so why not put something like this snippet in the while loop
    `
    $user_id = bp_get_member_user_id();
    $data = get_user_meta($user_id, ‘newfield’);
    if ( $data )
    echo “New Field Label: $data “;
    `

    Avatar of valuser
    valuser
    Participant

    @valuser

    Many, many thanks. Thrilled to bits!

    Added true for $single and thats it !

    `

    <?php $user_id = bp_get_member_user_id(); $data = get_user_meta($user_id, 'newfield',true);if ( $data ) echo "New Field Label: $data “; ?>

    `

    Avatar of valuser
    valuser
    Participant

    @valuser

Viewing 3 replies - 1 through 3 (of 3 total)

You must be logged in to reply to this topic.