Check if taxonomy term exists and save the term if it doesn't

A dynamic query can be used to check if a taxonomy term exists.

Query conditions are the taxonomy term name and the vocabulary.

Programatically delete taxonomy terms Drupal 7

By calling function taxonomy_get_tree($vid, $parent = 0, $depth = -1, $max_depth = NULL), an array of all term objects is returned. Extra parameters can be added to the function to select all items belonging to a particular parent or limit depth of the tree. By calling function taxonomy_term_delete($tid), a new db_transaction() starts and the taxonomy object and all its children are deleted from the taxomy_term_data and taxonomy_term_hierarchy tables. As a taxonomy term is an entity which has attached fields, all attached field data is also deleted. Finally, the function clears all static cache variables for terms by using taxonomy_terms_static_reset().

Remove the taxonomy description field Drupal 7

The description field from taxonomy terms is a property of the taxonomy term entity and can't be deleted. It isn't a field coming from the field module but its values are stored inside the taxonomy_term_data table. Use hook_form_id_alter(&form, &form_state, $form_id) to access the taxonomy term form. This hook is placed inside a custom module.

Programatically add taxonomy vocabularies

In this example a tax_creator module is used to install vocabularies when activating the module and to delete the vocabularies when uninstalling. This is really timesaving when dealing with many vocabularies as the only thing needed to do is to build a vocabulary array and activate the module. Comment hook_uninstall when uninstalling so taxonomy categories are kept. 

Programatically create taxonomy terms

Writing code to create multiple taxonomy items without a parent is really easy. Function taxonomy_term_save($term) requires an object as parameter. An array containing the term name and the vocabulary where to insert is parsed as an object and added as argument. This example shows inserting data in its simplest form, only a name and a vocabulary id is needed.

Subscribe to RSS - Taxonomy