I want to write a function that returns users which have entered a certain value to a custom user field.

Lets say there is a custom birthday field for every user. What would be the best way to get all users with a certain birthday?

I could create a DB query that searches the field_data_field_birthday table and returns the entity_id(s) (which in this case would be the users id(s)) for which the field_birthday_value matches a given value and then load the user(s).

This seems a little bit crude, are there generic functions for this use case available? In the entity API or the field API maybe?


1 Answer 1


Simple example for the use case I asked about:

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

$result = $query->execute();
$users_ids = array_keys($result['user']);
  • Worked like a charm.
    – Anders
    Commented Apr 20, 2013 at 20:38
  • Please advise the namespace to include for this to avoid Fatal Error.
    – Pupil
    Commented Jul 8, 2019 at 10:20

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.