By Jordan Weinstein on Monday, 04 December 2017
Posted in General Issues
Replies 9
Likes 0
Views 444
Votes 0
Hello,

Can you suggest a code snippet to retrieve the first name and last name from a EasySocial profile. I will be asking for no further support or customization - would just like to retrieve first and last name separately with some PHP to display.

Thanks for considering.

Jordan
Hey Jordan,

You could run the following query to get the user's name object,

[gist]
$my = ES::user();
$data = $my->getFieldValue('JOOMLA_FULLNAME');

// $data->first - First name
// $data->middle - Middle name
// $data->last - Last name
// $data->name - Full name
var_dump($data);
[/gist]

To get the correct field code (By default it should be JOOMLA_FULLNAME, unless you changed it) edit the name field and you should be able to see it, http://take.ms/yWqit
·
Monday, 04 December 2017 23:28
·
0 Likes
·
0 Votes
·
0 Comments
·
Thanks Mark!
·
Monday, 04 December 2017 23:35
·
0 Likes
·
0 Votes
·
0 Comments
·
You are most welcome
·
Monday, 04 December 2017 23:49
·
0 Likes
·
0 Votes
·
0 Comments
·
Sorry Mark, just to be clear if I want to simply echo first name what should I use after:



$my = ES::user();
$data = $my->getFieldValue('JOOMLA_FULLNAME');


I can't seem to echo the first name. I tried"

echo "$my->$data->first;"

and this showed:

SocialUser->Jordan;
·
Tuesday, 05 December 2017 00:35
·
0 Likes
·
0 Votes
·
0 Comments
·
Hey Jordan,

If you just want to display the first name, this is how you would do it:

[gist]
$my = ES::user();
$data = $my->getFieldValue('JOOMLA_FULLNAME');

echo $data->first;
[/gist]
·
Tuesday, 05 December 2017 01:19
·
0 Likes
·
0 Votes
·
0 Comments
·
Thanks Mark,

Final question when using your snippet above, the first name shows for logged in user. But for guests, rather than simply being blank (which I would expect and which happens for last name), this language string appears:

COM_EASYSOCIAL_GUEST_NAME
·
Tuesday, 05 December 2017 03:49
·
0 Likes
·
0 Votes
·
0 Comments
·
Hey Jordan,

Since guests does not have a name, I think your code should be something like this:

[gist]
$my = ES::user();

if ($my->id) {
$data = $my->getFieldValue('JOOMLA_FULLNAME');
echo $data->first;
}
[/gist]
·
Tuesday, 05 December 2017 09:46
·
0 Likes
·
0 Votes
·
0 Comments
·
Awesome, thanks Mark! No more questions,
·
Tuesday, 05 December 2017 21:56
·
0 Likes
·
0 Votes
·
0 Comments
·
You are most welcome Jordan. Have a great day ahead!
·
Tuesday, 05 December 2017 22:09
·
0 Likes
·
0 Votes
·
0 Comments
·
View Full Post