WordPress.org

Support

Support » Plugins and Hacks » [Resolved] wp_set_object_terms doesn't work in init?

[Resolved] wp_set_object_terms doesn't 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/

Viewing 1 replies (of 1 total)
  • Plugin Author Rachel Carden

    @bamadesigner

    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 ‘[Resolved] wp_set_object_terms doesn't work in init?’ is closed to new replies.