Title: wp_set_object_terms doesn&#039;t work in init?
Last modified: August 21, 2016

---

# wp_set_object_terms doesn't work in init?

 *  Resolved [Matt Lowe](https://wordpress.org/support/users/squelch/)
 * (@squelch)
 * [12 years, 1 month ago](https://wordpress.org/support/topic/wp_set_object_terms-doesnt-work-in-init/)
 * Hey,
 * I’ve written a function to collect some data from the front-end of a site and
   create a custom post type, then associate that CPT (which is a CPT-onomy) with
   another CPT using
 * `$cpt_onomy-> wp_set_object_terms( ... )`
 * I was doing this in a function that hooked `init`. I ran into an issue where 
   I kept getting a WP Error object returned with the message “Invalid taxonomy”.
   The CPT-onomy was correctly registered and I checked that the taxonomy was definitely
   registered by hooking the `registered_taxonomy` action. In the end I tried a 
   later action; Instead of `init` I hooked `wp_loaded` and my problem vanished.
 * So I suppose my question is which action do you recommend hooking for this kind
   of task? What’s the earliest action we can hook such that we don’t get in there
   before CPT-onomies has had a chance to set everything up appropriately?
 * Great plugin by the way. Awesome idea and great documentation.
 * [https://wordpress.org/plugins/cpt-onomies/](https://wordpress.org/plugins/cpt-onomies/)

Viewing 1 replies (of 1 total)

 *  [Rachel Cherry](https://wordpress.org/support/users/bamadesigner/)
 * (@bamadesigner)
 * [12 years, 1 month ago](https://wordpress.org/support/topic/wp_set_object_terms-doesnt-work-in-init/#post-4881505)
 * I would recommend using ‘wp_loaded’. The CPT-onomies are registered on the ‘init’
   hook so everything should be good to go by ‘wp_loaded’.
 * And thanks! Glad you like it!

Viewing 1 replies (of 1 total)

The topic ‘wp_set_object_terms doesn't work in init?’ is closed to new replies.

 * ![](https://s.w.org/plugins/geopattern-icon/cpt-onomies_f2f2f2.svg)
 * [CPT-onomies: Using Custom Post Types as Taxonomies](https://wordpress.org/plugins/cpt-onomies/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/cpt-onomies/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/cpt-onomies/)
 * [Active Topics](https://wordpress.org/support/plugin/cpt-onomies/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/cpt-onomies/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/cpt-onomies/reviews/)

## Tags

 * [cpt](https://wordpress.org/support/topic-tag/cpt/)
 * [init](https://wordpress.org/support/topic-tag/init/)

 * 1 reply
 * 2 participants
 * Last reply from: [Rachel Cherry](https://wordpress.org/support/users/bamadesigner/)
 * Last activity: [12 years, 1 month ago](https://wordpress.org/support/topic/wp_set_object_terms-doesnt-work-in-init/#post-4881505)
 * Status: resolved