How to retrieve usermeta data on members page ?
-
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 "<span>New Field Label: $data </span>"; } add_action( 'bp_directory_members_item', 'getnewfield' );
But it has not retrieved the data. ?
<hr class=”bbcode_rule” />
> the data is in the wp_usermeta database for each user_idAny 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+
-
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 "<span>New Field Label: $data </span>";
Many, many thanks. Thrilled to bits!
Added true for $single and thats it !
<div class="item-meta"><?php $user_id = bp_get_member_user_id(); $data = get_user_meta($user_id, 'newfield',true);if ( $data ) echo "<span>New Field Label: $data </span>"; ?></div>
Have posted a follow on topic at https://buddypress.org/community/groups/how-to-and-troubleshooting/forum/topic/search-bp-members-by-wp_usermeta-fields/
- The topic ‘How to retrieve usermeta data on members page ?’ is closed to new replies.