Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

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
add comment

1 Answer

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
3  
+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
1  
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? –  mazzzzz Nov 3 '12 at 21:25
add comment

Your Answer

 
discard

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.