Skip to content

Instantly share code, notes, and snippets.

@mqanneh
Forked from midnai/nodes of taxonomy.php
Created November 30, 2018 18:12
Show Gist options
  • Select an option

  • Save mqanneh/5fb07162d1e545c0543350f47a4b10e6 to your computer and use it in GitHub Desktop.

Select an option

Save mqanneh/5fb07162d1e545c0543350f47a4b10e6 to your computer and use it in GitHub Desktop.
get nodes of taxonomy term(s) in drupal 8
function getNodesByTaxonomyTermIds($termIds){
$termIds = (array) $termIds;
if(empty($termIds)){
return NULL;
}
$query = \Drupal::database()->select('taxonomy_index', 'ti');
$query->fields('ti', array('nid'));
$query->condition('ti.tid', $termIds, 'IN');
$query->distinct(TRUE);
$result = $query->execute();
if($nodeIds = $result->fetchCol()){
return Node::loadMultiple($nodeIds);
}
return NULL;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment