Ask your WordPress questions! Pay money and get answers fast! (more info)

Adding info from Buddypress xprofile fields under profile picture WordPress

  • SOLVED

Hi,

I want to add info from their profile xfield to their profile avatar in their member header. They are two different way to do it. But it's an issue. It seems when using this code it duplicates the information in the profile fields.


Here is the member-header.php is located: buddypress\members\single\member-header.php

<?php
$profession = bp_get_member_profile_data( 'field=Profession' );
echo '<span class="profile-fields"> Profession : </span><span class="status">' .$profession. '</span>';
?>


or

Add this code to the child theme function

add_action( 'bp_profile_header_meta', 'display_user_color_pref' );
function display_user_color_pref() {
$args = array(
'field' => 'Available for freelance?', // Field name or ID.
);
$freelance = bp_get_member_profile_data( $args );

if ($freelance) {
echo '<span class="profile-fields"> Freelance : ' .$freelance. '</span>';
}

}



They work but the issue is duplicated content in the xprofile tab instead. Can be theme related.

Answers (1)

2014-07-23

timDesain Nanang answers:

copy the <strong>profile-loop.php</strong> file,
from : /plugins/buddypress/bp-themes/bp-default/members/single/profile
to : /your-theme/buddypress/members/single/profile

then, edit the file
and put this code :
<?php
$field_name = bp_get_the_profile_field_name();
if ( $field_name=='Profession' OR $field_name=='Location' OR $field_name=='Expertise' OR $field_name=='Freelance' ) // change the field name
continue;
?>


after line 19 :

<?php if ( bp_field_has_data() ) : ?>


timDesain Nanang comments:

or you can copy the profile-loop.php file from the parent theme.


Veritus comments:

I'll check this out right away Tim. Should i leave the code that i have in the member-header.php be?

<?php
$profession = bp_get_member_profile_data( 'field=Profession' );
echo '<span class="profile-fields"> Profession : </span><span class="status">' .$profession. '</span>';
?>
<?php
$location = bp_get_member_profile_data( 'field=Location' );
echo '<span class="profile-fields"> Location : </span><span class="status">' .$location. '</span>';
?>
<?php
$expertise = bp_get_member_profile_data( 'field=Expertise' );
echo '<span class="profile-fields"> Expertise : </span><span class="status">' .$expertise. '</span>';
?>
<?php
$freelance = bp_get_member_profile_data( 'field=Available for freelance?' );
echo '<span class="profile-fields"> Freelance : </span><span class="status">' .$freelance. '</span>';
?>


timDesain Nanang comments:

no, you should remove the code inside member-header.php file

you can use this hooking instead, and put the code into the function

add_action( 'bp_profile_header_meta', 'display_user_color_pref' );
function display_user_color_pref() {
//put the code here

}


timDesain Nanang comments:

Those two methods gave the same output, you should choose one
I prefer choose the hook method


Veritus comments:

oki, deleting the code. You were to see what happens the code in the member-header.php


Veritus comments:

Working perfectly besides that it's added over the navigation icons.. I want it under the profile picture..


timDesain Nanang comments:

try to move the hooking :

change :
add_action( 'bp_profile_header_meta', 'display_user_color_pref' );

to:
add_action( 'bp_before_member_header_meta', 'display_user_color_pref', 4 );


timDesain Nanang comments:

or try using custom hooking

#1. copy the member-header.php file,
from : /plugins/buddypress/bp-themes/bp-default/members/single/ or from parent theme
to : /your-theme/buddypress/members/single/

#2. put this code :
<?php do_action( 'wpq_member_header' ); ?>
before:
<?php do_action( 'bp_before_member_header_meta' ); ?>

#3. then, put this code in the theme's functions.php

add_action( 'wpq_member_header', 'display_user_color_pref' );
function display_user_color_pref() {
echo '<div class="wpq-member-header">';

$profession = bp_get_member_profile_data( 'field=Profession' );
if($profession<>'')
echo '<span class="profile-fields"> Profession : </span><span class="status">' .$profession. '</span>';

$location = bp_get_member_profile_data( 'field=Location' );
if($location<>'')
echo '<span class="profile-fields"> Location : </span><span class="status">' .$location. '</span>';

$expertise = bp_get_member_profile_data( 'field=Expertise' );
if($expertise<>'')
echo '<span class="profile-fields"> Expertise : </span><span class="status">' .$expertise. '</span>';

$freelance = bp_get_member_profile_data( 'field=Available for freelance?' );
if($freelance<>'')
echo '<span class="profile-fields"> Freelance : </span><span class="status">' .$freelance. '</span>';

echo '</div>';
}


Veritus comments:

Yes, thank you Tim! But as you saw, there is another problem..