You can use EntityFieldQuery class to query the database and fetch the results in form of list similar to node_load_multiple()
.
This can be achieved by creating a class, applying the conditions and executing the query, for example:
<?php
$query = new EntityFieldQuery();
$query
->entityCondition('entity_type', 'TYPE') // E.g. node, entityform, taxonomy_term
->entityCondition('bundle', 'BUNDLE')
->fieldCondition('field_foo', 'value', 'STRING')
->range(0,10);
$result = $query->execute();
?>
This will generate the array such like:
array (
'TYPE' =>
array (
123 =>
stdClass::__set_state(array(
'nid' => '123', // Can be also tid when loading terms.
'key' => 'value',
)),
456 =>
stdClass::__set_state(array(
'nid' => '456',
'key' => 'value',
)),
),
)
To fetch the ID from the result array, you can use: current(current($result))->tid
.
Here is more advanced example:
<?php
$query = new EntityFieldQuery();
$query->entityCondition('entity_type', 'node')
->entityCondition('bundle', 'article')
->propertyCondition('status', NODE_PUBLISHED)
->fieldCondition('field_news_types', 'value', 'spotlight', '=')
->fieldCondition('field_photo', 'fid', 'NULL', '!=')
->fieldCondition('field_faculty_tag', 'tid', $value)
->fieldCondition('field_news_publishdate', 'value', $year . '%', 'like')
->fieldOrderBy('field_photo', 'fid', 'DESC')
->range(0, 10)
->addMetaData('account', user_load(1)); // Run the query as user 1.
$result = $query->execute();
if (isset($result['node'])) {
$news_items_nids = array_keys($result['node']);
$news_items = entity_load('node', $news_items_nids);
}
?>
See: How to use EntityFieldQuery at Drupal.org for more explanation.