The edit_term WordPress PHP action fires after a term has been updated, but before the term cache has been cleaned. The edit_$taxonomy
hook is also available for targeting a specific taxonomy.
Usage
add_action('edit_term', 'your_custom_function', 10, 4); function your_custom_function($term_id, $tt_id, $taxonomy, $args) { // your custom code here }
Parameters
- $term_id (int) – Term ID.
- $tt_id (int) – Term taxonomy ID.
- $taxonomy (string) – Taxonomy slug.
- $args (array) – Arguments passed to
wp_update_term()
.
More information
See WordPress Developer Resources: edit_term
Examples
Updating term meta on term edit
add_action('edit_term', 'update_term_meta_on_edit', 10, 4); function update_term_meta_on_edit($term_id, $tt_id, $taxonomy, $args) { update_term_meta($term_id, 'custom_term_meta_key', 'custom_value'); }
Log term updates
add_action('edit_term', 'log_term_updates', 10, 4); function log_term_updates($term_id, $tt_id, $taxonomy, $args) { error_log("Term ID {$term_id} in taxonomy {$taxonomy} has been updated."); }
Send an email notification when a specific taxonomy term is updated
add_action('edit_term', 'send_email_on_taxonomy_term_update', 10, 4); function send_email_on_taxonomy_term_update($term_id, $tt_id, $taxonomy, $args) { if ($taxonomy === 'custom_taxonomy') { // Send email notification } }
Change term parent when updated
add_action('edit_term', 'change_term_parent_on_update', 10, 4); function change_term_parent_on_update($term_id, $tt_id, $taxonomy, $args) { if ($taxonomy === 'category') { wp_update_term($term_id, $taxonomy, array('parent' => 3)); } }
Add a custom class to term on update
add_action('edit_term', 'add_custom_class_to_term_on_update', 10, 4); function add_custom_class_to_term_on_update($term_id, $tt_id, $taxonomy, $args) { update_term_meta($term_id, 'custom_term_class', 'your-custom-class'); }