Drupal - How to get nodes with term programmatically

You want to specify that you searching for nodes first (and optionally by your content type), and then filter by term:

$query = new EntityFieldQuery();
$query->entityCondition('entity_type', 'node')
->entityCondition('bundle', 'YOUR_CONTENT_TYPE_HERE')
->fieldCondition('field_game', 'tid', 5);

$result = $query->execute();
$nids = array_keys($result['node']);
$nodes = entity_load('node', $nids);

Here's a good example of an entity query like this (and more field conditions)


There is an API function taxonomy_select_nodes() for that:

$tid = 5;
$nids = taxonomy_select_nodes($tid, FALSE); // FALSE for paging.
$nodes = node_load_multiple($nids);

Tags:

Database

7