Exporting/Importing Taxonomy in Drupal 6

April 7, 2011
blog author

rllabore

Developer

I worked on a project which has about 400+ terms in one vocabulary. Writing a script that would manually add each term or just maintaining the the vocabulary would be nightmare. taxonomy_export module provided me the tool that can manage and track taxonomy changes. Here is how I used taxonomy_export to manage my vocabularies and terms:

1. Navigate to admin/content/taxonomy/export

2. Select the vocabulary that you want to export

3. Check Include Terms?

4. Check Save export as a file?

5. Click Export

6. Save the file somewhere in a custom module.

7. Write a script that would import the taxonomy file that you have downloaded.

function MODULE_NAME_update_XX() {   module_load_include('inc', 'taxonomy_export', 'taxonomy_export.pages');
  $path = drupal_get_path('module', 'MODULE_NAME') . '/FOLDER_NAME/NAME_OF_VOCAB.taxonomy_export.inc';
  $exported_file = file_get_contents($path, FILE_USE_INCLUDE_PATH);
  $form_state = NULL;   $form_state['values']['import_data'] = $exported_file;
  // create a new vocabulary   $form_state['values']['update'] = NULL;
  drupal_execute('taxonomy_export_import', $form_state);
  return array(     array(       'success' => TRUE,       'query' => 'Export vocabulary',     ),   ); }