The edit_{$taxonomy} WordPress PHP action fires after a term in a specific taxonomy has been updated, but before the term cache has been cleaned. The dynamic portion of the hook name, $taxonomy, refers to the taxonomy slug. Possible hook names include edit_category and edit_post_tag.
Usage
add_action('edit_{$taxonomy}', 'your_custom_function', 10, 3);
function your_custom_function($term_id, $tt_id, $args) {
// your custom code here
}
Parameters
$term_id(int) – Term ID.$tt_id(int) – Term taxonomy ID.$args(array) – Arguments passed towp_update_term().
More information
See WordPress Developer Resources: edit_{$taxonomy}
Examples
Log term updates
Log term updates for a custom taxonomy called genre.
add_action('edit_genre', 'log_term_updates', 10, 3);
function log_term_updates($term_id, $tt_id, $args) {
error_log("Term {$term_id} in 'genre' taxonomy has been updated.");
}
Send email notification
Send email notification when a category term is updated.
add_action('edit_category', 'send_email_notification', 10, 3);
function send_email_notification($term_id, $tt_id, $args) {
$to = '[email protected]';
$subject = 'Category updated';
$message = "Category with ID {$term_id} has been updated.";
wp_mail($to, $subject, $message);
}
Update a custom field
Update a custom field when a post tag is updated.
add_action('edit_post_tag', 'update_custom_field', 10, 3);
function update_custom_field($term_id, $tt_id, $args) {
update_term_meta($term_id, 'custom_field', 'updated_value');
}
Change parent term
Change the parent term of a custom taxonomy called location.
add_action('edit_location', 'change_parent_term', 10, 3);
function change_parent_term($term_id, $tt_id, $args) {
$new_parent_term_id = 5;
wp_update_term($term_id, 'location', array('parent' => $new_parent_term_id));
}
Update term count
Update term count for a custom taxonomy called color.
add_action('edit_color', 'update_term_count', 10, 3);
function update_term_count($term_id, $tt_id, $args) {
$term = get_term($term_id, 'color');
$new_count = $term->count + 1;
update_term_meta($term_id, 'term_count', $new_count);
}