In Drupal, I want to read a custom field value for a group of users while logged into an admin account. I only need 1 field value from each user, the same field and I do not need this information cached.
When I use user_load
it requests the user object as I only need one field this is very inefficient.
So I investigated field_get_items
, but I cannot see how to use this function without first using user_load
. I have attached my code and MARKED the line that is giving me an issue.
how can I use
field_get_items
without usinguser_load
, if not possible is there a efficient way of doing this? Please don't mentionuser_load_multiple
with user_load does setting , $reset = TRUE prevent Drupal caching the data or does it force a cache reset, get the data from the DB and then re-cache the new data?
Code I use:
$user_a = array(); // This is the array of URIs we need to query
foreach ($user_a AS $uid){
$account = user_load($uid, $reset = TRUE); // access the user objects, one at a time
$fullname[$uid] = $account->field_fullname[LANGUAGE_NONE][0]['value']; // extract value
}
$user_a = array(); // This is the array of URIs we need to query
foreach ($user_a AS $uid){
**$account = user_load($uid, $reset = TRUE);**
$fullname[$uid] = field_get_items('user', $account, 'field_fullname'); // extract array
foreach ($fullname[$uid] as $item) {
$fullname[$uid] = $item['value']; // extract value
}
}