2

I would like to use register_taxonomy() to define a hierarchy of geographical terms. It seems that the natural place to place it would be in a function called by register_activation_hook() seeing how the taxonomy needs only to be defined once. However, the fine manual explicitly states to "use the init action to call this function".

Why? Is the data not stored in the database but rather in memory? If so, might such taxonomies become memory hogs? I cannot anticipate where the end user might use the taxonomies to target anything more precise than init.

4

Is the data not stored in the database but rather in memory?

Taxonomies (like post types) aren't store in database and needs to be registered on every page load. The build in taxonomies, category and post_tag are actually registered twice, the second time on the init hook.

The init hook is the earliest to register taxonomies and post types because this is the hook where localization becomes available. This has become the accepted hook to register post types and taxonomies.

If so, might such taxonomies become memory hogs?

No. If you are going to register tons of taxonomies (or post types) it might become an issue, but doing that would point to a flaw in your design.

Terms on the other hand needs to be be registered once as they are stored in db. Here the register_activation_hook() is useful to register terms on plugin activation. Here is an example on how to register terms on plugin activation

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.