WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

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

How to add automatically keyword to taxonomies when a post published, and assign them to the post for example i have in my post edition, a custom meta box, when you complete this input, a function should generate a group of keywords in background , and i want these keywords are automatically adding to a specific custom taxonomy in that post when it published, this is possible? i try with


and nothing working great, thx

sorry for my worst english

share|improve this question
up vote 3 down vote accepted

You would use the save_post hook, in your hooked function use wp_insert_term as described here:


Then use wp_set_object_terms on the post to assignt he taxonomy term you just created as follows:


for example:

function my_save($post_id) {
    wp_insert_term( 'bannanapost', 'fruit');
    wp_set_object_terms( $post_id, 'bannanapost', 'fruit', true )

The above code, placed in functions.php of your theme, would add the term 'bannanapost' to each post when saved, in the fruit taxonomy

share|improve this answer
thanks a lot Tom – zagriyen Sep 10 '10 at 10:46
You don't need to use wp_insert_term, the term is automatically created if it doesn't exist. – Stephen Harris Mar 13 '12 at 10:28

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.