taxonomy.module関数のリストにある、私が望んでいるように見える唯一の関数は、プライベート関数(_taxonomy_get_tid_from_term)のように見えます。
分類用語名のみがわかっていて、そのIDを調べる必要がある場合、どの関数を使用することになっていますか?
taxonomy.module関数のリストにある、私が望んでいるように見える唯一の関数は、プライベート関数(_taxonomy_get_tid_from_term)のように見えます。
分類用語名のみがわかっていて、そのIDを調べる必要がある場合、どの関数を使用することになっていますか?
回答:
それはだtaxonomy_get_term_by_name()次のコードのように使用します。
$term_array = taxonomy_get_term_by_name('Foo');
$term = reset($term_array); # get the first element of the array which is our term object
print $term->name;foreach ($terms as $term)からチェックし$term->vidて、正しいボキャブラリーがあることを確認します。
                    taxonomy_get_term_by_name() トリックを行います:
$terms = taxonomy_get_term_by_name($row->field_term_name);
if (!empty($terms)) {
  $first_term = array_shift($terms);
  print $first_term->tid;
}$first_term = array_shift($terms);
                    この機能は私のために働いた:
/**
 * Return the term id for a given term name.
 */
function _get_tid_from_term_name($term_name) {
  $vocabulary = 'tags';
  $arr_terms = taxonomy_get_term_by_name($term_name, $vocabulary);
  if (!empty($arr_terms)) {
    $arr_terms = array_values($arr_terms);
    $tid = $arr_terms[0]->tid;
  }
  else {
    $vobj = taxonomy_vocabulary_machine_name_load($vocabulary);
    $term = new stdClass();
    $term->name = $term_name;
    $term->vid = $vobj->vid;
    taxonomy_term_save($term);
    $tid = $term->tid;
  }
  return $tid;
}別のボキャブラリー(タグとは異なる)を使用している場合は、次の行のコードを変更します。
$vocabulary = 'tags';
$foo[0]->tidTIDをキーとする配列を返すため、何もしません。TIDを取得するには、TIDが必要foreach()ですか、それとも1つのアイテムにしかありませんか?それ以外の場合:Undefined offset: 0