Answer the question
In order to leave comments, you need to log in
On what event do wp_insert_term?
Good afternoon, dear senior WP developers and in general those who can answer me.
I'm a little confused about the WP hook system. I am writing a plugin for WP, I have a task to create several types of posts and add about 20000 taxonomy terms, it would be logical to do this when installing the plugin via register_activation_hook. But according to the documentation and examples, record types are hung on the init hook.
Answer the question
In order to leave comments, you need to log in
1. Registration of custom record types and other goodies occurs on init, because otherwise, they simply will not be in the system (although the entries related to them may be in the database). So, register_custom_post_type and register_taxonomy simply change global variables.
2. But wp_insert_term needs to be called only once. It must be understood that it is different from all these register_taxonomyand other things by the fact that it writes data not to a global variable for the needs of the kernel, but to the database, and, accordingly, repeated calls will lead to data duplication at best. Event? The same init will do, just don't forget to put some kind of flag or a banal check for the existence of taxonomies / terms. Some is_terms_added in wp_options .
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question