7.x taxonomy.module taxonomy_term_delete($tid)

Delete a term.


$tid: The term ID.

Return value

Status constant indicating deletion.

8 calls to taxonomy_term_delete()
EntityCrudHookTestCase::testTaxonomyTermHooks in modules/simpletest/tests/entity_crud_hook_test.test
Tests hook invocations for CRUD operations on taxonomy terms.
ForumTestCase::testAddOrphanTopic in modules/forum/forum.test
Tests that forum nodes can't be added without a parent.
forum_confirm_delete_submit in modules/forum/forum.admin.inc
Form submission handler for forum_confirm_delete().
TaxonomyHooksTestCase::testTaxonomyTermHooks in modules/taxonomy/taxonomy.test
Test that hooks are run correctly on creating, editing, viewing, and deleting a term.
TaxonomyLoadMultipleTestCase::testTaxonomyTermMultipleLoad in modules/taxonomy/taxonomy.test
Create a vocabulary and some taxonomy terms, ensuring they're loaded correctly using taxonomy_term_load_multiple().

... See full list

1 string reference to 'taxonomy_term_delete'


modules/taxonomy/taxonomy.module, line 708
Enables the organization of content into categories.


function taxonomy_term_delete($tid) {
  $transaction = db_transaction();
  try {
    $tids = array(
    while ($tids) {
      $children_tids = $orphans = array();
      foreach ($tids as $tid) {

        // See if any of the term's children are about to be become orphans:
        if ($children = taxonomy_get_children($tid)) {
          foreach ($children as $child) {

            // If the term has multiple parents, we don't delete it.
            $parents = taxonomy_get_parents($child->tid);
            if (count($parents) == 1) {
              $orphans[] = $child->tid;
        if ($term = taxonomy_term_load($tid)) {
            ->condition('tid', $tid)
            ->condition('tid', $tid)
          field_attach_delete('taxonomy_term', $term);
          module_invoke_all('taxonomy_term_delete', $term);
          module_invoke_all('entity_delete', $term, 'taxonomy_term');
      $tids = $orphans;
    return SAVED_DELETED;
  } catch (Exception $e) {
    watchdog_exception('taxonomy', $e);
    throw $e;


nicrodgers’s picture

To delete a term in D8, you can use:

$controller = \Drupal::entityTypeManager()->getStorage('taxonomy_term');
$term = $controller->load($tid);