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.
Use the action
created_term
. Its first parameter is the$term_id
.It is called in
wp_insert_term()
inwp-includes/taxonomy.php
after a term was successful created: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 â¦
⦠and your callback should look like this: