Skip to content

Instantly share code, notes, and snippets.

@batandwa
Created February 20, 2014 08:43
Show Gist options
  • Select an option

  • Save batandwa/9109350 to your computer and use it in GitHub Desktop.

Select an option

Save batandwa/9109350 to your computer and use it in GitHub Desktop.
Get nodes of term and it child terms
<?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