How to create a taxonomy

Importing vocabulary and terms together

Function used: install_taxonomy_import().

The goal is to define a complete taxonomy (vocabulary and the relevant terms) in one big associative array. Due to the nature of the term and vocabulary import functions this might seem redundant at first, but individual vocabulary and term creation is covered later on.

The example array is quite self-explanatory:


$taxonomy = array(
  0 => array(
    'name' => 'vocab name',
    'content_types' => array(),
    'properties' => array(),
    'terms' => array(
      0 => array(
        'name' => 'Term Name',
        'description' => '',
        'properties' => array(),
      )
    ),
  ),
);

install_taxonomy_import($taxonomy);

It is important to note that even though description and properties are empty here, they still must be set. Otherwise we will encounter an "unsupported operand types in taxonomy.module" error, which is a sign that, you are probably not using the correct array structure. Once again, term description and properties must not be omitted, even if empty!

Creating vocabularies

Function used: install_taxonomy_add_vocabulary()

Subscribe with RSS Subscribe to RSS - create taxanomy