0
$vocabulary = (object) array(
'name' => st('A'),
'description' => st('A'),
'machine_name' => 'user_a',
'help' => 'test for subterm',
);
taxonomy_vocabulary_save($vocabulary);

$user_a=array(st('A'),st('B'));

$user_a_vid=db_select('taxonomy_vocabulary', 'tv')
  ->fields('tv', array('vid'))
  ->condition('machine_name', 'user_a')
  ->execute()
  ->fetchField();

foreach ($user_a as $name) {
    $term = new stdClass;
    $term->name = $name;
    $term->vid = $user_a_vid;
    taxonomy_term_save($term);
 }

i have two vocabulary A and B

and i want to add sub-term of A and B

A have sub-term 1,2 B have sub-term 3,4

how can i do that in code?

Thanks for reading my question~thx~

1

Yeh~

i found out,this code can fix all the problem

$term->parent = $parent_tid;
| improve this answer | |
0

Depending on your use case, you may be able to use the Taxonomy CSV module. This module allows you to create a CSV file and import taxonomy vocabularies (including subterms/hierarchy structures).

| improve this answer | |
  • thx for sharing, but i want to write a .install file and create taxonomy by program. But this module is still useful for me. Thx a lot ! Do u know how to write the code? – cobenash Jun 26 '12 at 7:01

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.