WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I'm taking my first foray into plugin development and have got confused pretty quickly. I'm attempting to make a simple plugin that stores hex colours against terms, so you can assign a colour to a tag or category and then use that in a theme.

What I cant figure out is how to get the term_id of a newly created or edited term. I've bolted on a form to 'edit_tag_form' with a colour picker and can access these values through $_POST, but if it's a newly created tag I don't see how my code can know the ID of the newly created one. I need to know the term_id to be able to link it with the hex colour and save it to wp_options.

I'm using the action hook 'edited_term'. I guess for edited existing terms I could get the tag_ID from the query string, but I want to be able to assign colours immediately to newly created tags/categories.

share|improve this question
up vote 1 down vote accepted

Use the action created_term. Its first parameter is the $term_id.

It is called in wp_insert_term() in wp-includes/taxonomy.php after a term was successful created:

do_action("created_term", $term_id, $tt_id, $taxonomy);
do_action("created_$taxonomy", $term_id, $tt_id);

The second parameter is the term_taxonomy_id from the term_taxonomy table, and the last parameter is the taxonomy.

So register an action with …

add_action( 'created_term', 'wpse_78858_add_color', 10, 3 );

… and your callback should look like this:

function wpse_78858_add_color( $term_id, $tt_id, $taxonomy )
    # do something
share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.