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
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()$defaultintThe 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: falseOptional. 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
- Scaling
- Scales with input
- Instructions
- 13–234
- Plugin surface
- 7 hooks
- Called by
- 7
Reaches the database via ->get_col().
The body loops, so the work grows with what you pass in.
Executed per call on PHP 8.5, depending on the branch taken. The body compiles to 295.
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.
7 places in core call this, so the cost is paid more often than your own code shows.
What it touches
- optionoption read or write
get_option()called directly - hookthird-party callbacks
do_action()called directly - querycontent query
get_term()called directly - sqldatabase query
->get_col()called directly - cacheobject cache
wp_cache_get()one call below wp_delete_term() - serializeserialisation
maybe_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.
| When | Instructions | Calls it makes |
|---|---|---|
| always | 13 | term_exists() |
is_wp_error() | 17 | term_exists(), is_wp_error() |
!is_wp_error() && $taxonomy === "category" && $term === false | 31 | term_exists(), is_wp_error(), get_option() |
!is_wp_error() && $taxonomy !== "category" && !empty($taxonomy_object) && $term === false | 38 | term_exists(), is_wp_error(), get_taxonomy(), get_option() |
!is_wp_error() && $taxonomy === "category" && !empty($taxonomy_object) | 47 | term_exists(), is_wp_error(), get_option(), get_taxonomy(), get_option() |
$taxonomy !== "category" && empty($taxonomy_object) && !isset($args) && is_taxonomy_hierarchical() | 55–57 | term_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–66 | term_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–66 | term_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–67 | term_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–75 | term_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–76 | term_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–76 | term_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–85 | term_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–139 | term_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–146 | term_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–148 | term_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–148 | term_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–149 | term_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–155 | term_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–155 | term_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–156 | term_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–157 | term_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–158 | term_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–158 | term_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–164 | term_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–165 | term_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–165 | term_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–167 | term_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–174 | term_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–199 | term_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–206 | term_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–208 | term_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–208 | term_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–209 | term_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–215 | term_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–215 | term_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–216 | term_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–217 | term_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–218 | term_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–218 | term_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–224 | term_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–225 | term_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–225 | term_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–227 | term_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–234 | term_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:
- 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.
- do_action( edit_term_taxonomies )actionline 2131 (+74 into the body)
Fires immediately before a term to delete's children are reassigned a parent.
- do_action( edited_term_taxonomies )actionline 2146 (+89 into the body)
Fires immediately after a term to delete's children are reassigned a parent.
- do_action( delete_term_taxonomy )actionline 2200 (+143 into the body)
Fires immediately before a term taxonomy ID is deleted.
- do_action( deleted_term_taxonomy )actionline 2211 (+154 into the body)
Fires immediately after a term taxonomy ID is deleted.
- do_action( delete_term )actionline 2235 (+178 into the body)
Fires after a term is deleted from the database and the cache is cleaned.
- do_action( delete_{$taxonomy} )actionline 2256 (+199 into the body)
Fires after a term in a specific taxonomy is deleted.
Uses · 15
- term_exists()Determines whether a taxonomy term exists.
- is_wp_error()Checks whether the given variable is a WordPress Error.
- get_option()Retrieves an option value based on an option name.
- get_taxonomy()Retrieves the taxonomy object of $taxonomy.
- wp_parse_args()Merges user defined arguments into defaults array.
- do_action()Calls the callback functions that have been added to an action hook.
- is_taxonomy_hierarchical()Determines whether the taxonomy object is hierarchical.
- get_term()Gets all term data from database by term ID.
- wp_list_pluck()Plucks a certain field out of each object or array in an array.
- clean_term_cache()Removes all of the term IDs from the cache.
- wp_remove_object_terms()Removes term(s) associated with a given object.
- wp_get_object_terms()Retrieves the terms associated with the given object(s), in the supplied taxonomies.
Show all 15
- wp_set_object_terms()Creates term and taxonomy relationships.
- clean_object_term_cache()Removes the taxonomy relationship to terms from the cache.
- delete_metadata_by_mid()Deletes metadata by meta ID.
Used by · 7
- WP_REST_Terms_Controller::delete_item()Deletes a single term from a taxonomy.
- upgrade_350()Execute changes made in WordPress 3.5.
- wp_ajax_delete_tag()Handles deleting a tag via AJAX.
- wp_delete_category()Deletes one existing category.
- wp_delete_nav_menu()Deletes a navigation menu.
- wp_xmlrpc_server::wp_deleteCategory()Deletes a category.
- wp_xmlrpc_server::wp_deleteTerm()Deletes a term.
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.
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.