edited_(taxonomy)action-hookWP 2.3.0

Fires after a term (category or other taxonomy item) has been updated and its cache cleared.

For example, it lets you create or update term meta fields on the term editing page.

See also the identical edited_term hook, where the taxonomy name is passed in the third parameter. Otherwise, the hook works the same way.

Possible hook names:

The dynamic (taxonomy) part of the hook name is the name (slug) of the taxonomy to work with. For the built-in WordPress taxonomies, the hook looks like this:

  • edited_category — when a category is edited.
  • edited_post_tag — when a tag is edited.
  • post_format — when a post format is edited.
  • nav_menu — when a navigation menu is edited.

Usage

add_action( 'edited_(taxonomy)', 'wp_kama_edited_taxonomy_action', 10, 3 );

/**
 * Function for `edited_(taxonomy)` action-hook.
 * 
 * @param int   $term_id Term ID.
 * @param int   $tt_id   Term taxonomy ID.
 * @param array $args    Arguments passed to wp_update_term().
 *
 * @return void
 */
function wp_kama_edited_taxonomy_action( $term_id, $tt_id, $args ){

	// action...
}
$term_id(int)
Term ID.
$tt_id(int)
Term ID including the taxonomy (an internal parameter; in recent WordPress versions, it is equal to the term ID).
$args(array) (WP 6.1)
Arguments passed to wp_update_term().

Examples

#1 Save a custom field after editing a term (category)

<?php
// Add a custom field to the editing form.
add_action( 'category_edit_form_fields', 'add_custom_form_field' );

function add_custom_form_field( $term ) {
	?>
	<tr class="form-field">
		<th scope="row" valign="top"><label><?php _e( 'Custom field' ); ?></label></th>
		<td>
			<input type="text" name="custom_field" value="<?php esc_attr_e( get_term_meta( $term->term_id, 'custom_field', true ) ) ?>">
		</td>
	</tr>
	<?php
}

// Save the custom field value.
add_action( 'edited_category', 'save_custom_form_field' );
function save_custom_form_field( $term_id ) {

	if ( ! isset( $_POST['custom_field'] ) ) {
		return;
	}

	if ( ! current_user_can( 'edit_term', $term_id ) ) {
		return;
	}

	if ( ! wp_verify_nonce( $_POST['_wpnonce'], "update-tag_{$term_id}" ) && ! wp_verify_nonce( $_POST['_wpnonce_add-tag'], 'add-tag' ) ) {
		return;
	}

	update_term_meta( $term_id, 'custom_field', wp_unslash( $_POST['custom_field'] ) );

	return $term_id;
}

Changelog

Since 2.3.0 Introduced.
Since 6.1.0 The $args parameter was added.

Where the hook is called

wp_update_term()
edited_(taxonomy)
wp-includes/taxonomy.php 3535
do_action( "edited_{$taxonomy}", $term_id, $tt_id, $args );

Where the hook is used in WordPress

Usage not found.