Created
February 20, 2014 08:43
-
-
Save batandwa/9109350 to your computer and use it in GitHub Desktop.
Get nodes of term and it child terms
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
| <?php | |
| /** | |
| * Uses the passed in term and its children and gets the associated nodes. Pass | |
| * the returned array into entity_load to load the nodes. | |
| * | |
| * @author Batandwa Colani | |
| * @date 2014-02-20 | |
| * @version 1 | |
| * | |
| * @param int $tid The parent term id | |
| * @return array The node ids | |
| */ | |
| function term_recursive_nodes($tid) { | |
| $query = new EntityFieldQuery(); | |
| $query->entityCondition('entity_type', 'node') | |
| ->entityCondition('bundle', 'service_provider') | |
| ->fieldCondition('field_solutions', 'tid', array_merge(array($tid), array_keys(taxonomy_get_children($tid))), 'IN'); | |
| $result = $query->execute(); | |
| if(!empty($result)) { | |
| $nids = array_keys($result['node']); | |
| // $nodes = entity_load('node', $nids); | |
| return $nids; | |
| } | |
| return array(); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment