3

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?

1
  • Updated the title to better describe the question being asked.
    – t31os
    Commented Dec 18, 2010 at 13:37

1 Answer 1

5

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

2
  • 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
    Commented Dec 18, 2010 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?
    – Jess
    Commented Nov 3, 2012 at 21:25

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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