Using WordPress ‘edited_term_taxonomy’ PHP action

The edited_term_taxonomy WordPress PHP action fires immediately after a term-taxonomy relationship is updated.

Usage

add_action('edited_term_taxonomy', 'my_custom_function', 10, 3);

function my_custom_function($tt_id, $taxonomy, $args) {
    // your custom code here
}

Parameters

  • $tt_id (int): Term taxonomy ID.
  • $taxonomy (string): Taxonomy slug.
  • $args (array): Arguments passed to wp_update_term().

More information

See WordPress Developer Resources: edited_term_taxonomy

Examples

Log term-taxonomy update

Log when a term-taxonomy relationship is updated.

add_action('edited_term_taxonomy', 'log_term_taxonomy_update', 10, 3);

function log_term_taxonomy_update($tt_id, $taxonomy, $args) {
    error_log("Term taxonomy {$tt_id} ({$taxonomy}) updated.");
}

Clear cache on update

Clear cache when a term-taxonomy relationship is updated.

add_action('edited_term_taxonomy', 'clear_cache_on_term_taxonomy_update', 10, 3);

function clear_cache_on_term_taxonomy_update($tt_id, $taxonomy, $args) {
    wp_cache_delete("term_taxonomy_{$tt_id}_{$taxonomy}", 'my_custom_cache_group');
}

Send email notification

Send an email notification when a term-taxonomy relationship is updated.

add_action('edited_term_taxonomy', 'send_email_on_term_taxonomy_update', 10, 3);

function send_email_on_term_taxonomy_update($tt_id, $taxonomy, $args) {
    $admin_email = get_option('admin_email');
    wp_mail($admin_email, 'Term Taxonomy Updated', "Term taxonomy {$tt_id} ({$taxonomy}) has been updated.");
}

Update custom meta

Update custom meta when a term-taxonomy relationship is updated.

add_action('edited_term_taxonomy', 'update_custom_meta_on_term_taxonomy_update', 10, 3);

function update_custom_meta_on_term_taxonomy_update($tt_id, $taxonomy, $args) {
    update_term_meta($tt_id, 'my_custom_meta_key', 'my_custom_meta_value');
}

Add a prefix to term description

Add a prefix to the term description when a term-taxonomy relationship is updated.

add_action('edited_term_taxonomy', 'add_prefix_to_term_description', 10, 3);

function add_prefix_to_term_description($tt_id, $taxonomy, $args) {
    if (isset($args['description'])) {
        $new_description = 'Prefix: ' . $args['description'];
        wp_update_term($tt_id, $taxonomy, array('description' => $new_description));
    }
}