-
-
Save mqanneh/5fb07162d1e545c0543350f47a4b10e6 to your computer and use it in GitHub Desktop.
get nodes of taxonomy term(s) in drupal 8
This file contains hidden or 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