0

I have a added data to the user using:

taxonomy_term_reference

when creating the

field_create_instance($instance)

and everything is working fine, I can add and store values and these are added to the specified vocabulary.

The problem is, I cannot extract the value added as a term to the $user object using field_get_items and field_view_value since field_get_items('user', $user, 'field_name') is empty.

Is field_get_items and field_view_value not applicable to $user?

1 Answer 1

3

I was experiencing the same issue. field_get_items was always empty when trying to get a field attached to a user. The problem was that the $user object you get when you do a

global $user

isn't the full entity. So when you pass it into the field_get_items function, it doesn't match anything.

Do a full user_load on the $user->uid and THEN pass the resulting object to field_get_items, and everything should work.

1
  • Sounds reasonable, I did var_dump the entire $user and could see it wasn't complete, and field_get_items does something link $entity->{field_name} so the data if present when field_get_items is called Commented Feb 22, 2012 at 6:15

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.