Well, I found a Backdrop CMS test that created a vocabulary and some terms and that was really helpful.
// Create a vocabulary and a term
$vocabulary = new TaxonomyVocabulary(array(
'name' => 'Class',
'description' => '',
'machine_name' => 'animal_class',
));
taxonomy_vocabulary_save($vocabulary);
$term = entity_create('taxonomy_term', array(
'name' => 'Mammalia',
'description' => '',
'format' => 1,
'vocabulary' => 'animal_class',
));
taxonomy_term_save($term);
I was then able to do this to add it to a node programmatically (see here for the rest of the code to add a node).
$node->field_animal_class['und'][0]['tid'] = '1';
I haven't figured out how to add a term to a node without knowing the TID.
I would think that I could add a term to the vocabulary, just by adding it to the node directory. But, I could not get that to work. Ideas?
Well, I found a Backdrop CMS test that created a vocabulary and some terms and that was really helpful.
I was then able to do this to add it to a node programmatically (see here for the rest of the code to add a node).
I haven't figured out how to add a term to a node without knowing the TID.
I would think that I could add a term to the vocabulary, just by adding it to the node directory. But, I could not get that to work. Ideas?