End of life
As of December 31st, 2011,Taxonomy Builder API has reached “end of life” and is deprecated in favor of Taxonomy CSV import/export. Please post an issue if you feel this module is still valuable and wish to pick up maintainership.
API
The example below creates a simple hierarchy of countries, states, and cties.
// Replace with whatever vocabulary ID the terms should be added to.
$vid = 12;
// Hierarchy arrays.
$hierarchies = array(
array('United states', 'Massachusetts', 'Boston'),
array('United states', 'Massachusetts', 'Worcester'),
array('United states', 'New York', 'New York'),
array('United states', 'New York', 'Albany'),
);
// Adds terms to the taxonomy hierarchy one by one. This makes it easy to
// break up large trees via the batch API so the build doesn't time out.
foreach ($hierarchies as $hierarchy) {
taxonomy_builder_save_terms($vid, $hierarchy);
}
This produces a taxonomy tree with the following structure: