Created
February 8, 2018 06:29
-
-
Save midnai/d828328995205a657bb59dbfef52ff7f to your computer and use it in GitHub Desktop.
get nodes of taxonomy term(s) in drupal 8
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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