wppaste
WordPress

wp_delete_term( int $term, string $taxonomy, array|string $args = array() ): bool|int|WP_Error

Since
2.3.0
Source
wp-includes/taxonomy.php:2057
Removes a term from the database.

Description

If the term is a parent of other terms, then the children will be updated to that term's parent.

Metadata associated with the term will be deleted.

Compatibility

WordPress
since 2.3.0
PHP
7.4–8.6-dev
  • 6.7.7
  • 6.8.8
  • 6.9.7
  • 7.0.4
  • 7.1.0

Present in every tracked release (6.7.7 to 7.1.0), and compiles on PHP 7.4 through 8.6-dev.

Parameters

$termint
Term ID.
$taxonomystring
Taxonomy name.
$argsarray|stringoptional
Array of arguments to override the default term ID. Default empty array.Default: array()
  • $defaultint

    The term ID to make the default term. This will only override the terms found if there is only one term found. Any other and the found terms are used.
  • $force_defaultbooldefault: false

    Optional. Whether to force the supplied term as default to be assigned even if the object was not going to be term-less.

Return value

bool|int|WP_Error
True on success, false if term does not exist. Zero on attempted deletion of default Category. WP_Error if the taxonomy does not exist.

Performance profile

How much work a call to wp_delete_term() does, and what it touches: the algorithmic scaling, the Zend instruction count per call across PHP versions, the hooks it hands control to, and the core code that calls it. Measured from the compiled opcodes, not a stopwatch, so every number is identical on any machine running the same PHP version, and every function in core is ranked by cost.

Cost class
Heavy

Reaches the database via ->get_col().

Scaling
Scales with input

The body loops, so the work grows with what you pass in.

Instructions
13–234

Executed per call on PHP 8.5, depending on the branch taken. The body compiles to 295.

Plugin surface
7 hooks

Third-party callbacks on 'pre_delete_term', 'edit_term_taxonomies', 'edited_term_taxonomies' run inside this call, and their cost is not bounded by anything here.

Called by
7

7 places in core call this, so the cost is paid more often than your own code shows.

What it touches

  • optionoption read or writeget_option()called directly
  • hookthird-party callbacksdo_action()called directly
  • querycontent queryget_term()called directly
  • sqldatabase query->get_col()called directly
  • cacheobject cachewp_cache_get()one call below wp_delete_term()
  • serializeserialisationmaybe_unserialize()one call below wp_delete_term()

Further down the call graph this can also reach transient. That is the worst case, several calls deep and usually down an error path, not what a normal call pays.

What one call costs · 45 distinct outcomes

One number would be a lie: the work depends on which branch runs. These are every distinct cost wp_delete_term() can have, taken from its control-flow graph on PHP 8.5.

WhenInstructionsCalls it makes
always13term_exists()
is_wp_error()17term_exists(), is_wp_error()
!is_wp_error() && $taxonomy === "category" && $term === false31term_exists(), is_wp_error(), get_option()
!is_wp_error() && $taxonomy !== "category" && !empty($taxonomy_object) && $term === false38term_exists(), is_wp_error(), get_taxonomy(), get_option()
!is_wp_error() && $taxonomy === "category" && !empty($taxonomy_object)47term_exists(), is_wp_error(), get_option(), get_taxonomy(), get_option()
$taxonomy !== "category" && empty($taxonomy_object) && !isset($args) && is_taxonomy_hierarchical()55–57term_exists(), is_wp_error(), get_taxonomy(), wp_parse_args(), do_action(), is_taxonomy_hierarchical(), get_term(), is_wp_error()
$taxonomy !== "category" && empty($taxonomy_object) && isset($args) && is_taxonomy_hierarchical()63–66term_exists(), is_wp_error(), get_taxonomy(), wp_parse_args(), term_exists(), do_action(), is_taxonomy_hierarchical(), get_term(), is_wp_error()
$taxonomy === "category" && $term !== false && empty($taxonomy_object) && !isset($args) && is_taxonomy_hierarchical()64–66term_exists(), is_wp_error(), get_option(), get_taxonomy(), wp_parse_args(), do_action(), is_taxonomy_hierarchical(), get_term(), is_wp_error()
$taxonomy !== "category" && !empty($taxonomy_object) && $term !== false && !isset($args) && is_taxonomy_hierarchical()65–67term_exists(), is_wp_error(), get_taxonomy(), get_option(), wp_parse_args(), do_action(), is_taxonomy_hierarchical(), get_term(), is_wp_error()
$taxonomy === "category" && $term !== false && empty($taxonomy_object) && isset($args) && is_taxonomy_hierarchical()72–75term_exists(), is_wp_error(), get_option(), get_taxonomy(), wp_parse_args(), term_exists(), do_action(), is_taxonomy_hierarchical(), get_term(), is_wp_error()
$taxonomy !== "category" && !empty($taxonomy_object) && $term !== false && isset($args) && is_taxonomy_hierarchical()73–76term_exists(), is_wp_error(), get_taxonomy(), get_option(), wp_parse_args(), term_exists(), do_action(), is_taxonomy_hierarchical(), get_term(), is_wp_error()
$taxonomy === "category" && $term !== false && !empty($taxonomy_object) && !isset($args) && is_taxonomy_hierarchical()74–76term_exists(), is_wp_error(), get_option(), get_taxonomy(), get_option(), wp_parse_args(), do_action(), is_taxonomy_hierarchical(), get_term(), is_wp_error()
33 further outcomes, up to 234 instructions
$taxonomy === "category" && $term !== false && !empty($taxonomy_object) && isset($args) && is_taxonomy_hierarchical()82–85term_exists(), is_wp_error(), get_option(), get_taxonomy(), get_option(), wp_parse_args(), term_exists(), do_action(), is_taxonomy_hierarchical(), get_term(), is_wp_error()
!is_wp_error() && $taxonomy !== "category" && empty($taxonomy_object) && !isset($args) && !is_taxonomy_hierarchical() && ->get_var()134–139term_exists(), is_wp_error(), get_taxonomy(), wp_parse_args(), do_action(), is_taxonomy_hierarchical(), get_term(), ->prepare(), ->get_col(), get_taxonomy(), ->prepare(), ->get_col(), do_action(), term_taxonomy_id(), do_action(), ->prepare(), ->get_var(), clean_term_cache(), do_action(), do_action()
!is_wp_error() && $taxonomy !== "category" && empty($taxonomy_object) && !isset($args) && !is_taxonomy_hierarchical() && !->get_var()141–146term_exists(), is_wp_error(), get_taxonomy(), wp_parse_args(), do_action(), is_taxonomy_hierarchical(), get_term(), ->prepare(), ->get_col(), get_taxonomy(), ->prepare(), ->get_col(), do_action(), term_taxonomy_id(), do_action(), ->prepare(), ->get_var(), term_id(), clean_term_cache(), do_action(), do_action()
!is_wp_error() && $taxonomy !== "category" && empty($taxonomy_object) && isset($args) && !is_taxonomy_hierarchical() && ->get_var()142–148term_exists(), is_wp_error(), get_taxonomy(), wp_parse_args(), term_exists(), do_action(), is_taxonomy_hierarchical(), get_term(), ->prepare(), ->get_col(), get_taxonomy(), ->prepare(), ->get_col(), do_action(), term_taxonomy_id(), do_action(), ->prepare(), ->get_var(), clean_term_cache(), do_action(), do_action()
!is_wp_error() && $taxonomy === "category" && $term !== false && empty($taxonomy_object) && !isset($args) && !is_taxonomy_hierarchical() && ->get_var()143–148term_exists(), is_wp_error(), get_option(), get_taxonomy(), wp_parse_args(), do_action(), is_taxonomy_hierarchical(), get_term(), ->prepare(), ->get_col(), get_taxonomy(), ->prepare(), ->get_col(), do_action(), term_taxonomy_id(), do_action(), ->prepare(), ->get_var(), clean_term_cache(), do_action(), do_action()
!is_wp_error() && $taxonomy !== "category" && !empty($taxonomy_object) && $term !== false && !isset($args) && !is_taxonomy_hierarchical() && ->get_var()144–149term_exists(), is_wp_error(), get_taxonomy(), get_option(), wp_parse_args(), do_action(), is_taxonomy_hierarchical(), get_term(), ->prepare(), ->get_col(), get_taxonomy(), ->prepare(), ->get_col(), do_action(), term_taxonomy_id(), do_action(), ->prepare(), ->get_var(), clean_term_cache(), do_action(), do_action()
!is_wp_error() && $taxonomy !== "category" && empty($taxonomy_object) && isset($args) && !is_taxonomy_hierarchical() && !->get_var()149–155term_exists(), is_wp_error(), get_taxonomy(), wp_parse_args(), term_exists(), do_action(), is_taxonomy_hierarchical(), get_term(), ->prepare(), ->get_col(), get_taxonomy(), ->prepare(), ->get_col(), do_action(), term_taxonomy_id(), do_action(), ->prepare(), ->get_var(), term_id(), clean_term_cache(), do_action(), do_action()
!is_wp_error() && $taxonomy === "category" && $term !== false && empty($taxonomy_object) && !isset($args) && !is_taxonomy_hierarchical() && !->get_var()150–155term_exists(), is_wp_error(), get_option(), get_taxonomy(), wp_parse_args(), do_action(), is_taxonomy_hierarchical(), get_term(), ->prepare(), ->get_col(), get_taxonomy(), ->prepare(), ->get_col(), do_action(), term_taxonomy_id(), do_action(), ->prepare(), ->get_var(), term_id(), clean_term_cache(), do_action(), do_action()
!is_wp_error() && $taxonomy !== "category" && !empty($taxonomy_object) && $term !== false && !isset($args) && !is_taxonomy_hierarchical() && !->get_var()151–156term_exists(), is_wp_error(), get_taxonomy(), get_option(), wp_parse_args(), do_action(), is_taxonomy_hierarchical(), get_term(), ->prepare(), ->get_col(), get_taxonomy(), ->prepare(), ->get_col(), do_action(), term_taxonomy_id(), do_action(), ->prepare(), ->get_var(), term_id(), clean_term_cache(), do_action(), do_action()
!is_wp_error() && $taxonomy === "category" && $term !== false && empty($taxonomy_object) && isset($args) && !is_taxonomy_hierarchical() && ->get_var()151–157term_exists(), is_wp_error(), get_option(), get_taxonomy(), wp_parse_args(), term_exists(), do_action(), is_taxonomy_hierarchical(), get_term(), ->prepare(), ->get_col(), get_taxonomy(), ->prepare(), ->get_col(), do_action(), term_taxonomy_id(), do_action(), ->prepare(), ->get_var(), clean_term_cache(), do_action(), do_action()
!is_wp_error() && $taxonomy !== "category" && !empty($taxonomy_object) && $term !== false && isset($args) && !is_taxonomy_hierarchical() && ->get_var()152–158term_exists(), is_wp_error(), get_taxonomy(), get_option(), wp_parse_args(), term_exists(), do_action(), is_taxonomy_hierarchical(), get_term(), ->prepare(), ->get_col(), get_taxonomy(), ->prepare(), ->get_col(), do_action(), term_taxonomy_id(), do_action(), ->prepare(), ->get_var(), clean_term_cache(), do_action(), do_action()
!is_wp_error() && $taxonomy === "category" && $term !== false && !empty($taxonomy_object) && !isset($args) && !is_taxonomy_hierarchical() && ->get_var()153–158term_exists(), is_wp_error(), get_option(), get_taxonomy(), get_option(), wp_parse_args(), do_action(), is_taxonomy_hierarchical(), get_term(), ->prepare(), ->get_col(), get_taxonomy(), ->prepare(), ->get_col(), do_action(), term_taxonomy_id(), do_action(), ->prepare(), ->get_var(), clean_term_cache(), do_action(), do_action()
!is_wp_error() && $taxonomy === "category" && $term !== false && empty($taxonomy_object) && isset($args) && !is_taxonomy_hierarchical() && !->get_var()158–164term_exists(), is_wp_error(), get_option(), get_taxonomy(), wp_parse_args(), term_exists(), do_action(), is_taxonomy_hierarchical(), get_term(), ->prepare(), ->get_col(), get_taxonomy(), ->prepare(), ->get_col(), do_action(), term_taxonomy_id(), do_action(), ->prepare(), ->get_var(), term_id(), clean_term_cache(), do_action(), do_action()
!is_wp_error() && $taxonomy !== "category" && !empty($taxonomy_object) && $term !== false && isset($args) && !is_taxonomy_hierarchical() && !->get_var()159–165term_exists(), is_wp_error(), get_taxonomy(), get_option(), wp_parse_args(), term_exists(), do_action(), is_taxonomy_hierarchical(), get_term(), ->prepare(), ->get_col(), get_taxonomy(), ->prepare(), ->get_col(), do_action(), term_taxonomy_id(), do_action(), ->prepare(), ->get_var(), term_id(), clean_term_cache(), do_action(), do_action()
!is_wp_error() && $taxonomy === "category" && $term !== false && !empty($taxonomy_object) && !isset($args) && !is_taxonomy_hierarchical() && !->get_var()160–165term_exists(), is_wp_error(), get_option(), get_taxonomy(), get_option(), wp_parse_args(), do_action(), is_taxonomy_hierarchical(), get_term(), ->prepare(), ->get_col(), get_taxonomy(), ->prepare(), ->get_col(), do_action(), term_taxonomy_id(), do_action(), ->prepare(), ->get_var(), term_id(), clean_term_cache(), do_action(), do_action()
!is_wp_error() && $taxonomy === "category" && $term !== false && !empty($taxonomy_object) && isset($args) && !is_taxonomy_hierarchical() && ->get_var()161–167term_exists(), is_wp_error(), get_option(), get_taxonomy(), get_option(), wp_parse_args(), term_exists(), do_action(), is_taxonomy_hierarchical(), get_term(), ->prepare(), ->get_col(), get_taxonomy(), ->prepare(), ->get_col(), do_action(), term_taxonomy_id(), do_action(), ->prepare(), ->get_var(), clean_term_cache(), do_action(), do_action()
!is_wp_error() && $taxonomy === "category" && $term !== false && !empty($taxonomy_object) && isset($args) && !is_taxonomy_hierarchical() && !->get_var()168–174term_exists(), is_wp_error(), get_option(), get_taxonomy(), get_option(), wp_parse_args(), term_exists(), do_action(), is_taxonomy_hierarchical(), get_term(), ->prepare(), ->get_col(), get_taxonomy(), ->prepare(), ->get_col(), do_action(), term_taxonomy_id(), do_action(), ->prepare(), ->get_var(), term_id(), clean_term_cache(), do_action(), do_action()
!is_wp_error() && $taxonomy !== "category" && empty($taxonomy_object) && !isset($args) && is_taxonomy_hierarchical() && ->get_var()194–199term_exists(), is_wp_error(), get_taxonomy(), wp_parse_args(), do_action(), is_taxonomy_hierarchical(), get_term(), is_wp_error(), ->get_results(), wp_list_pluck(), do_action(), compact(), compact(), parent(), wp_list_pluck(), clean_term_cache(), do_action(), get_term(), ->prepare(), ->get_col(), get_taxonomy(), ->prepare(), ->get_col(), do_action(), term_taxonomy_id(), do_action(), ->prepare(), ->get_var(), clean_term_cache(), do_action(), do_action()
!is_wp_error() && $taxonomy !== "category" && empty($taxonomy_object) && !isset($args) && is_taxonomy_hierarchical() && !->get_var()201–206term_exists(), is_wp_error(), get_taxonomy(), wp_parse_args(), do_action(), is_taxonomy_hierarchical(), get_term(), is_wp_error(), ->get_results(), wp_list_pluck(), do_action(), compact(), compact(), parent(), wp_list_pluck(), clean_term_cache(), do_action(), get_term(), ->prepare(), ->get_col(), get_taxonomy(), ->prepare(), ->get_col(), do_action(), term_taxonomy_id(), do_action(), ->prepare(), ->get_var(), term_id(), clean_term_cache(), do_action(), do_action()
!is_wp_error() && $taxonomy !== "category" && empty($taxonomy_object) && isset($args) && is_taxonomy_hierarchical() && ->get_var()202–208term_exists(), is_wp_error(), get_taxonomy(), wp_parse_args(), term_exists(), do_action(), is_taxonomy_hierarchical(), get_term(), is_wp_error(), ->get_results(), wp_list_pluck(), do_action(), compact(), compact(), parent(), wp_list_pluck(), clean_term_cache(), do_action(), get_term(), ->prepare(), ->get_col(), get_taxonomy(), ->prepare(), ->get_col(), do_action(), term_taxonomy_id(), do_action(), ->prepare(), ->get_var(), clean_term_cache(), do_action(), do_action()
!is_wp_error() && $taxonomy === "category" && $term !== false && empty($taxonomy_object) && !isset($args) && is_taxonomy_hierarchical() && ->get_var()203–208term_exists(), is_wp_error(), get_option(), get_taxonomy(), wp_parse_args(), do_action(), is_taxonomy_hierarchical(), get_term(), is_wp_error(), ->get_results(), wp_list_pluck(), do_action(), compact(), compact(), parent(), wp_list_pluck(), clean_term_cache(), do_action(), get_term(), ->prepare(), ->get_col(), get_taxonomy(), ->prepare(), ->get_col(), do_action(), term_taxonomy_id(), do_action(), ->prepare(), ->get_var(), clean_term_cache(), do_action(), do_action()
!is_wp_error() && $taxonomy !== "category" && !empty($taxonomy_object) && $term !== false && !isset($args) && is_taxonomy_hierarchical() && ->get_var()204–209term_exists(), is_wp_error(), get_taxonomy(), get_option(), wp_parse_args(), do_action(), is_taxonomy_hierarchical(), get_term(), is_wp_error(), ->get_results(), wp_list_pluck(), do_action(), compact(), compact(), parent(), wp_list_pluck(), clean_term_cache(), do_action(), get_term(), ->prepare(), ->get_col(), get_taxonomy(), ->prepare(), ->get_col(), do_action(), term_taxonomy_id(), do_action(), ->prepare(), ->get_var(), clean_term_cache(), do_action(), do_action()
!is_wp_error() && $taxonomy !== "category" && empty($taxonomy_object) && isset($args) && is_taxonomy_hierarchical() && !->get_var()209–215term_exists(), is_wp_error(), get_taxonomy(), wp_parse_args(), term_exists(), do_action(), is_taxonomy_hierarchical(), get_term(), is_wp_error(), ->get_results(), wp_list_pluck(), do_action(), compact(), compact(), parent(), wp_list_pluck(), clean_term_cache(), do_action(), get_term(), ->prepare(), ->get_col(), get_taxonomy(), ->prepare(), ->get_col(), do_action(), term_taxonomy_id(), do_action(), ->prepare(), ->get_var(), term_id(), clean_term_cache(), do_action(), do_action()
!is_wp_error() && $taxonomy === "category" && $term !== false && empty($taxonomy_object) && !isset($args) && is_taxonomy_hierarchical() && !->get_var()210–215term_exists(), is_wp_error(), get_option(), get_taxonomy(), wp_parse_args(), do_action(), is_taxonomy_hierarchical(), get_term(), is_wp_error(), ->get_results(), wp_list_pluck(), do_action(), compact(), compact(), parent(), wp_list_pluck(), clean_term_cache(), do_action(), get_term(), ->prepare(), ->get_col(), get_taxonomy(), ->prepare(), ->get_col(), do_action(), term_taxonomy_id(), do_action(), ->prepare(), ->get_var(), term_id(), clean_term_cache(), do_action(), do_action()
!is_wp_error() && $taxonomy !== "category" && !empty($taxonomy_object) && $term !== false && !isset($args) && is_taxonomy_hierarchical() && !->get_var()211–216term_exists(), is_wp_error(), get_taxonomy(), get_option(), wp_parse_args(), do_action(), is_taxonomy_hierarchical(), get_term(), is_wp_error(), ->get_results(), wp_list_pluck(), do_action(), compact(), compact(), parent(), wp_list_pluck(), clean_term_cache(), do_action(), get_term(), ->prepare(), ->get_col(), get_taxonomy(), ->prepare(), ->get_col(), do_action(), term_taxonomy_id(), do_action(), ->prepare(), ->get_var(), term_id(), clean_term_cache(), do_action(), do_action()
!is_wp_error() && $taxonomy === "category" && $term !== false && empty($taxonomy_object) && isset($args) && is_taxonomy_hierarchical() && ->get_var()211–217term_exists(), is_wp_error(), get_option(), get_taxonomy(), wp_parse_args(), term_exists(), do_action(), is_taxonomy_hierarchical(), get_term(), is_wp_error(), ->get_results(), wp_list_pluck(), do_action(), compact(), compact(), parent(), wp_list_pluck(), clean_term_cache(), do_action(), get_term(), ->prepare(), ->get_col(), get_taxonomy(), ->prepare(), ->get_col(), do_action(), term_taxonomy_id(), do_action(), ->prepare(), ->get_var(), clean_term_cache(), do_action(), do_action()
!is_wp_error() && $taxonomy !== "category" && !empty($taxonomy_object) && $term !== false && isset($args) && is_taxonomy_hierarchical() && ->get_var()212–218term_exists(), is_wp_error(), get_taxonomy(), get_option(), wp_parse_args(), term_exists(), do_action(), is_taxonomy_hierarchical(), get_term(), is_wp_error(), ->get_results(), wp_list_pluck(), do_action(), compact(), compact(), parent(), wp_list_pluck(), clean_term_cache(), do_action(), get_term(), ->prepare(), ->get_col(), get_taxonomy(), ->prepare(), ->get_col(), do_action(), term_taxonomy_id(), do_action(), ->prepare(), ->get_var(), clean_term_cache(), do_action(), do_action()
!is_wp_error() && $taxonomy === "category" && $term !== false && !empty($taxonomy_object) && !isset($args) && is_taxonomy_hierarchical() && ->get_var()213–218term_exists(), is_wp_error(), get_option(), get_taxonomy(), get_option(), wp_parse_args(), do_action(), is_taxonomy_hierarchical(), get_term(), is_wp_error(), ->get_results(), wp_list_pluck(), do_action(), compact(), compact(), parent(), wp_list_pluck(), clean_term_cache(), do_action(), get_term(), ->prepare(), ->get_col(), get_taxonomy(), ->prepare(), ->get_col(), do_action(), term_taxonomy_id(), do_action(), ->prepare(), ->get_var(), clean_term_cache(), do_action(), do_action()
!is_wp_error() && $taxonomy === "category" && $term !== false && empty($taxonomy_object) && isset($args) && is_taxonomy_hierarchical() && !->get_var()218–224term_exists(), is_wp_error(), get_option(), get_taxonomy(), wp_parse_args(), term_exists(), do_action(), is_taxonomy_hierarchical(), get_term(), is_wp_error(), ->get_results(), wp_list_pluck(), do_action(), compact(), compact(), parent(), wp_list_pluck(), clean_term_cache(), do_action(), get_term(), ->prepare(), ->get_col(), get_taxonomy(), ->prepare(), ->get_col(), do_action(), term_taxonomy_id(), do_action(), ->prepare(), ->get_var(), term_id(), clean_term_cache(), do_action(), do_action()
!is_wp_error() && $taxonomy !== "category" && !empty($taxonomy_object) && $term !== false && isset($args) && is_taxonomy_hierarchical() && !->get_var()219–225term_exists(), is_wp_error(), get_taxonomy(), get_option(), wp_parse_args(), term_exists(), do_action(), is_taxonomy_hierarchical(), get_term(), is_wp_error(), ->get_results(), wp_list_pluck(), do_action(), compact(), compact(), parent(), wp_list_pluck(), clean_term_cache(), do_action(), get_term(), ->prepare(), ->get_col(), get_taxonomy(), ->prepare(), ->get_col(), do_action(), term_taxonomy_id(), do_action(), ->prepare(), ->get_var(), term_id(), clean_term_cache(), do_action(), do_action()
!is_wp_error() && $taxonomy === "category" && $term !== false && !empty($taxonomy_object) && !isset($args) && is_taxonomy_hierarchical() && !->get_var()220–225term_exists(), is_wp_error(), get_option(), get_taxonomy(), get_option(), wp_parse_args(), do_action(), is_taxonomy_hierarchical(), get_term(), is_wp_error(), ->get_results(), wp_list_pluck(), do_action(), compact(), compact(), parent(), wp_list_pluck(), clean_term_cache(), do_action(), get_term(), ->prepare(), ->get_col(), get_taxonomy(), ->prepare(), ->get_col(), do_action(), term_taxonomy_id(), do_action(), ->prepare(), ->get_var(), term_id(), clean_term_cache(), do_action(), do_action()
!is_wp_error() && $taxonomy === "category" && $term !== false && !empty($taxonomy_object) && isset($args) && is_taxonomy_hierarchical() && ->get_var()221–227term_exists(), is_wp_error(), get_option(), get_taxonomy(), get_option(), wp_parse_args(), term_exists(), do_action(), is_taxonomy_hierarchical(), get_term(), is_wp_error(), ->get_results(), wp_list_pluck(), do_action(), compact(), compact(), parent(), wp_list_pluck(), clean_term_cache(), do_action(), get_term(), ->prepare(), ->get_col(), get_taxonomy(), ->prepare(), ->get_col(), do_action(), term_taxonomy_id(), do_action(), ->prepare(), ->get_var(), clean_term_cache(), do_action(), do_action()
!is_wp_error() && $taxonomy === "category" && $term !== false && !empty($taxonomy_object) && isset($args) && is_taxonomy_hierarchical() && !->get_var()228–234term_exists(), is_wp_error(), get_option(), get_taxonomy(), get_option(), wp_parse_args(), term_exists(), do_action(), is_taxonomy_hierarchical(), get_term(), is_wp_error(), ->get_results(), wp_list_pluck(), do_action(), compact(), compact(), parent(), wp_list_pluck(), clean_term_cache(), do_action(), get_term(), ->prepare(), ->get_col(), get_taxonomy(), ->prepare(), ->get_col(), do_action(), term_taxonomy_id(), do_action(), ->prepare(), ->get_var(), term_id(), clean_term_cache(), do_action(), do_action()

Across PHP versions

Compiles the same on PHP 7.4, 8.1, 8.2, 8.3, 8.4, 8.5 and 8.6-dev: 295 instructions, 13–234 executed per call, 22 branches. The work does not change between versions.

An instruction is not a fixed amount of time, so a matching count is not necessarily the same speed; what it rules out is a difference in the work itself.

Hooks and filters fired · 7

7 hooks fire while wp_delete_term() runs, in this order:

  1. do_action( pre_delete_term )actionline 2111 (+54 into the body)

    Fires when deleting a term, before any modifications are made to posts or terms.

  2. do_action( edit_term_taxonomies )actionline 2131 (+74 into the body)

    Fires immediately before a term to delete's children are reassigned a parent.

  3. do_action( edited_term_taxonomies )actionline 2146 (+89 into the body)

    Fires immediately after a term to delete's children are reassigned a parent.

  4. do_action( delete_term_taxonomy )actionline 2200 (+143 into the body)

    Fires immediately before a term taxonomy ID is deleted.

  5. do_action( deleted_term_taxonomy )actionline 2211 (+154 into the body)

    Fires immediately after a term taxonomy ID is deleted.

  6. do_action( delete_term )actionline 2235 (+178 into the body)

    Fires after a term is deleted from the database and the cache is cleaned.

  7. do_action( delete_{$taxonomy} )actionline 2256 (+199 into the body)

    Fires after a term in a specific taxonomy is deleted.

Uses · 15

Show all 15

Used by · 7

Source code

function wp_delete_term( $term, $taxonomy, $args = array() ) {	global $wpdb; 	$term = (int) $term; 	$ids = term_exists( $term, $taxonomy );	if ( ! $ids ) {		return false;	}	if ( is_wp_error( $ids ) ) {		return $ids;	} 	$tt_id = $ids['term_taxonomy_id']; 	$defaults = array(); 	if ( 'category' === $taxonomy ) {		$defaults['default'] = (int) get_option( 'default_category' );		if ( $defaults['default'] === $term ) {			return 0; // Don't delete the default category.		}	} 	// Don't delete the default custom taxonomy term.	$taxonomy_object = get_taxonomy( $taxonomy );	if ( ! empty( $taxonomy_object->default_term ) ) {		$defaults['default'] = (int) get_option( 'default_term_' . $taxonomy );		if ( $defaults['default'] === $term ) {			return 0;		}	} 	$args = wp_parse_args( $args, $defaults ); 	if ( isset( $args['default'] ) ) {		$default = (int) $args['default'];		if ( ! term_exists( $default, $taxonomy ) ) {			unset( $default );		}	} 	if ( isset( $args['force_default'] ) ) {		$force_default = $args['force_default'];	} 	/**	 * Fires when deleting a term, before any modifications are made to posts or terms.	 *	 * @since 4.1.0	 *	 * @param int    $term     Term ID.	 * @param string $taxonomy Taxonomy name.	 */	do_action( 'pre_delete_term', $term, $taxonomy ); 	// Update children to point to new parent.	if ( is_taxonomy_hierarchical( $taxonomy ) ) {		$term_obj = get_term( $term, $taxonomy );		if ( is_wp_error( $term_obj ) ) {			return $term_obj;		}		$parent = $term_obj->parent; 		$edit_ids    = $wpdb->get_results( "SELECT term_id, term_taxonomy_id FROM $wpdb->term_taxonomy WHERE `parent` = " . (int) $term_obj->term_id );		$edit_tt_ids = wp_list_pluck( $edit_ids, 'term_taxonomy_id' ); 		/**		 * Fires immediately before a term to delete's children are reassigned a parent.		 *		 * @since 2.9.0		 *		 * @param array $edit_tt_ids An array of term taxonomy IDs for the given term.		 */		do_action( 'edit_term_taxonomies', $edit_tt_ids ); 		$wpdb->update( $wpdb->term_taxonomy, compact( 'parent' ), array( 'parent' => $term_obj->term_id ) + compact( 'taxonomy' ) ); 		// Clean the cache for all child terms.		$edit_term_ids = wp_list_pluck( $edit_ids, 'term_id' );

Changelog

Introduced in 2.3.0. Unchanged from 6.7.7 through 7.1.0.

  1. 6.7.7
  2. 6.8.8
  3. 6.9.7
  4. 7.0.4
  5. 7.1.0

Signature, return type and hooks compared across 5 parsed releases.

About this page

Parsed data
Generated from the wordpress-develop 7.1.0 tag, from src/wp-includes/taxonomy.php, and regenerated for each WordPress release so it tracks the code rather than a snapshot of it.
Corrections
Something wrong on this page? Report it and it gets fixed in the next regeneration.