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

I'm registering taxonomy in my functions.php file:

register_taxonomy("our_gallery_types", array("gallery"), array("hierarchical" => true, "label" => "Categories", "singular_label" => "Category", "rewrite" => true));

And it works perfectly.

But I want also to automatically create two terms in this taxonomy, how would i do that?

When you run Wordpress for the very first time and click Posts there is "Uncategorized" category. I want to do exactly the same for my taxonomy, so my users won't get confused and won't have to create categories for their own.

How do i achieve that?

share|improve this question
Updated the title to better describe the question being asked. – t31os Dec 18 '10 at 13:37
up vote 4 down vote accepted

use wp_insert_term() (after you register the taxonomy)

You can also check if a term exists() before doing that, to save some useless db queries...

share|improve this answer
+1 and want to note that some kind of check is really necessary. While taxonomy registration is on the fly and in memory, terms are stored in database and should only be created once. – Rarst Dec 18 '10 at 13:29
Can term_exists be called on every page load? Or should I be careful to only put it on like a setup page or plugin activation? – Ben Nov 3 '12 at 21:25

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.