-
-
Save napoler/ba819e8190d51db1701c to your computer and use it in GitHub Desktop.
Drupal自动创建分类
This file contains 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
/** | |
* Return the term id for a given term name. | |
自动创建分类 | |
*/ | |
function _get_tid_from_term_name($term_name, $vocabulary = 'tags') { | |
// $vocabulary = 'zhonglei'; | |
$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; | |
} |
This file contains 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
try { | |
// node_save($node); | |
$developer_id = _get_tid_from_term_name($content[developer], $vocabulary = 'developer'); | |
} catch (exception $e) { | |
echo 'faill add developer.'; | |
} | |
$node->field_category[und][0]['tid'] = $developer_id; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment