2

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?

  • Updated the title to better describe the question being asked. – t31os Dec 18 '10 at 13:37
4

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...

| 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? – Ben Nov 3 '12 at 21:25

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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