drupal7 获取profile2模块自定义字段的值

$user=user_load($uid);
$student=profile2_load_by_user($user,'student');

这个函数官方有文档,通过用户对象返回用户的profile2的对象,当然可能用户定义了几个profile。我们用到的是student这个profile。
然后利用field_get_items()获得指定的字段
例如机房的机器名叫做machine_room.
使用

$machine_room=field_get_items('profile2',$student,'field_machine_room'));

结果返回的是一个数组,直接取出你想要的值就可以进行其他操作了。

原文出处:drupal7中利用profile2的api对使用profile2字段的对象进行操作|durpal profile2 api

原文地址:https://www.cnblogs.com/zjfblog/p/9681745.html