I have a profile field called "myutr" that I need to pass to the browser, for ALL pages, via js


I know that $user does not contain profile fields so to get the value of this field I need to load it via

$account = user_load($user);
drupal_add_js($account->myutr); //I know that is not the correct code

But in a big site with more and more page views call user_load only for a field is for me a bad perfomance practice. So: is there a possibility to load only this field via drupal standard api ? Or I need to call db_query(....) ?



Have a look at this article, I've used the method in the past.


  • Welcome to Drupal Answers! Whilst this may theoretically answer the question, it would be preferable to include the essential parts of the answer here, and provide the link for reference.
    – mpdonadio
    Jun 26 '14 at 19:33
  • field_view_field() and field_get_items() requires that entity is loaded. I don't want to load user fields only for 1 field (performance). However thanks.
    – ZioBudda
    Jun 27 '14 at 7:15

Entity Queries will probably work!

Taken from this answer: How to get users (entities) for a certain field value?

Just add in the condition for the current userid.

$query = new EntityFieldQuery();
$query->entityCondition('entity_type', 'user')
  ->fieldCondition('field_birthday', 'value', $birthday);

$result = $query->execute();
$users_ids = array_keys($result['user']);
  • I don't need to search users for a value, I need to get only 1 field's value for a user that I know (uid). But I don't want to load ALL users fields/data.
    – ZioBudda
    Jun 27 '14 at 7:18

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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