CPT-onomies: Using Custom Post Types as Taxonomies
[resolved] wp_set_object_terms doesn't work in init? (2 posts)

  1. Matt Lowe
    Posted 2 years ago #


    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.


  2. Rachel Carden
    Plugin Author

    Posted 2 years ago #

    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!

Topic Closed

This topic has been closed to new replies.

About this Plugin

About this Topic