Ok, I did it!
I wrote the following simple code – my custom field is country:
function xprofile_sync_extra_field_wp_profile( $user_id = 0 ) {
// Bail if profile syncing is disabled.
if ( bp_disable_profile_sync() ) {
return true;
}
if ( empty( $user_id ) ) {
$user_id = bp_loggedin_user_id();
}
if ( empty( $user_id ) ) {
return false;
}
//Get country info from xprofile
$country = xprofile_get_field_data('Country', $user_id);
if (!get_user_meta($user_id, 'country'))
{
add_user_meta($user_id, 'country', $country);
} else
bp_update_user_meta( $user_id, 'country', $country );
}
add_action( 'xprofile_updated_profile', 'xprofile_sync_extra_field_wp_profile' );
add_action( 'bp_core_signup_user', 'xprofile_sync_extra_field_wp_profile' );
add_action( 'bp_core_activated_user', 'xprofile_sync_extra_field_wp_profile' );
So, every time there is a new user, or a user is activated or the profile is updated, the custom field is being updated (or added) at the wp_usermeta table.
And I run first once the following in order to fill in key-value.
$users = get_users( array( 'fields' => array( 'id' ) ) );
foreach ($users as $user) {
$memberid = $user->id;
$country = xprofile_get_field_data('Country', $memberid);
if ($country) {
add_user_meta($memberid, 'country', $country);
//var_dump($country); die('kiki');
}
}
It works now very well!
Thank you for your support!