Using WordPress ‘edit_term_taxonomies’ PHP action

The edit_term_taxonomies WordPress PHP action fires immediately before a term’s children are reassigned a parent.

Usage

add_action('edit_term_taxonomies', 'your_custom_function');
function your_custom_function($edit_tt_ids) {
    // your custom code here
}

Parameters

  • $edit_tt_ids (array): An array of term taxonomy IDs for the given term.

More information

See WordPress Developer Resources: edit_term_taxonomies

Examples

Log term taxonomy IDs

Log the term taxonomy IDs before the term’s children are reassigned.

add_action('edit_term_taxonomies', 'log_term_taxonomy_ids');
function log_term_taxonomy_ids($edit_tt_ids) {
    error_log(print_r($edit_tt_ids, true));
}

Send an email notification

Send an email notification when a term’s children are about to be reassigned.

add_action('edit_term_taxonomies', 'send_email_notification');
function send_email_notification($edit_tt_ids) {
    // Email recipients and subject
    $to = '[email protected]';
    $subject = 'Term children reassignment';

    // Prepare the message body
    $message = "The following term taxonomy IDs are about to have their children reassigned:\n\n";
    $message .= implode(', ', $edit_tt_ids);

    // Send the email
    wp_mail($to, $subject, $message);
}

Update term meta

Update the term meta for each term before their children are reassigned.

add_action('edit_term_taxonomies', 'update_term_meta_before_reassignment');
function update_term_meta_before_reassignment($edit_tt_ids) {
    foreach ($edit_tt_ids as $term_taxonomy_id) {
        update_term_meta($term_taxonomy_id, 'children_reassigned', true);
    }
}

Custom action before reassignment

Perform a custom action for each term before their children are reassigned.

add_action('edit_term_taxonomies', 'custom_action_before_reassignment');
function custom_action_before_reassignment($edit_tt_ids) {
    foreach ($edit_tt_ids as $term_taxonomy_id) {
        // Perform custom action
    }
}

Delete term meta

Delete a specific term meta for each term before their children are reassigned.

add_action('edit_term_taxonomies', 'delete_term_meta_before_reassignment');
function delete_term_meta_before_reassignment($edit_tt_ids) {
    foreach ($edit_tt_ids as $term_taxonomy_id) {
        delete_term_meta($term_taxonomy_id, 'specific_meta_key');
    }
}