1

I have taxonomies and sub-taxonomies :

 - MainTaxo
    - SubTaxo1
    - SubTaxo2

taxonomy_select_nodes give me all ids of the selected taxonomy but if I put the MainTaxo id, it don't return me ids of SubTaxo1 and SubTaxo2.

$ids = taxonomy_select_nodes($mainTaxonomy_id, false);

Is there a native drupal function or should I do a query for that?

4

2 回答 2

3

这是我最后所做的:

/**
 * function to get all node ids recursively inside a taxonomy term.
 * Returns Flat array of nids.
 * @param
 *   $tid takes tid for which you need nids recursively.
 * @return
 *   $nids flat array of nids
 */
function get_all_nodes_belong_to_taxonomy_hierarchy($tid) {
  $taxonomies   = array('parent' => (int)$tid);
  $taxonomies = $taxonomies + array_keys(taxonomy_get_children($tid));
  $nids = array();

  foreach ($taxonomies as $taxonomy_id) {
    $nodes = taxonomy_select_nodes($taxonomy_id, false);
    $nids = array_merge_recursive($nids, $nodes);
  }
  return $nids;
}
于 2013-09-06T09:41:17.830 回答
2

没有原生的 Drupal 功能,但在这个链接中有替代品!

https://drupal.org/node/1946346

我希望它有用。

问候。

于 2013-09-05T15:54:09.570 回答