LoginSignup
0
0

More than 5 years have passed since last update.

Drupal7でmachine_nameからtaxonomyを取得する

Posted at

taxonomy_node_get_terms_by_vocabulary関数はdrupal7では用意されていないので、明示的に定義する必要があります。

関数

function taxonomy_node_get_terms_by_vocabulary($node, $vid) {
    $terms = &drupal_static(__FUNCTION__, array());

    if (!isset($terms[$vid])) {
      $terms[$vid] = array();
    }

    if (!isset($terms[$vid][$nid])) {
      $query = db_select('taxonomy_term_data', 'td')
        ->fields('td', array('tid'))
        ->condition('td.vid', $vid)
        ->condition('i.nid', $node->nid)
        ->orderBy('td.weight');

      $query->join('taxonomy_index', 'i', 'i.tid = td.tid');

      $terms[$vid][$nid] = taxonomy_term_load_multiple($query->execute()->fetchCol());
    }

    return $terms[$vid][$nid];
  }

あとはこいつを呼んでやってください

参考サイト

IS there a replacement for 'taxonomy_node_get_terms_by_vocabulary' in Drupal 7?

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0