Hi,
I make a registration form with profile2 and some fields.
I want to fetch family field with name: field_family
I used this code to display specified field:

<?php
global $user;
$uid = user_load($user->uid);
$profile_somename = profile2_load_by_user($uid, 'profile_main');
print ($profile_somename->field_family['und'][0]['value']);
?>

but it doesn't work!

Comments

rajiv.singh’s picture

global $user;
//you do not need this below line
//$uid = user_load($user->uid);

  $profile = profile2_load_by_user($user->uid);

	//Example: get user's first name from prof 
	if ($profile['profile_main']->field_custom_first_name) {
		$user_name = $profile['profile_main']->field_custom_first_name['und'][0]['value']; 
	} 

//Example :-
	if ($profile) { 
		$pid = $profile['profile_main']->pid;
 		//you can grab profile fields render array from user object using the pid 
		$profile_fields = $user->content['profile_profile_main']['view']['profile2'][$pid];	
		// see in devel :)
		dsm($profile_fields);				
	}