Query custom field on user table How do you query custom fields on the user table? If edit a user in the Admin panel, and hit the DEVEL tab, I see the field I added, 'field_display_name'.

In a node template php file, I want to replace the 'name' field with 'field_display_name'.

When I query, either using:

$result = db_select('users', 'u')
  -&gt;fields('u')
  -&gt;condition('name', 'bubba', '=')
  -&gt;execute()
  -&gt;fetchAssoc();


or

$rst = db_query("select * from {users} where name = :name", array(':name' =&gt; 'bubba',));


neither one of these return my custom field on the user table. (DPM does not show field_display_name)

So obviously, i'm missing something fundamental in my understanding of the data structure. 

How do i return this added field by querying with uid or name to return and print the 'field_display_name' ?
Entity fields are in their own separate table(s), they don't get attached to the base entity table.

You can use an EntityFieldQuery to get that data:

$query = new \EntityFieldQuery();
$query-&gt;entityCondition('entity_type', 'user')
  -&gt;fieldCondition('field_display_name', 'value', 'bubba');

$results = $query-&gt;execute();
if (!empty($results['user'])) {
  $users = user_load_multiple(array_keys($results['user']));
}


See Where does Drupal 7 store custom user account fields? for a bit more info