I see a couple similar questions here, but they appear to be either directed at registration process, and involve editing core plugin - or they reference what I am already trying to do (but for me its not working!) In this case, I am trying to relate existing registered cpt's and tax,and do it via a custom function, so that I can update the plugin itself without issue, and none of the answers seem to relate specifically:
I have some EXISTING custom post types (registered via 3rd party plugin) to which I need to link standard categories. I have done this before to the standard pages post type without issue, but for some reason I can't get it to work for these cpts.
Before someone asks, I verified that I am using the correct post_type name via the posts table in the database, to be sure I am using the proper names. I am applying the following to my custom functions:
if ( ! function_exists('cptpages_register_taxonomy') ) {
function cptpages_register_taxonomy() {
register_taxonomy_for_object_type('category', 'my-topics');
register_taxonomy_for_object_type('category', 'my-assignments');
register_taxonomy_for_object_type('category', 'my-certificates');
}
add_action('plugins_loaded', 'cptpages_register_taxonomy');
}
I have also tried it with add_action('init'... but to no avail. Assuming I have the names correct, what might be stopping this assignment from working??
Thanks for any thoughts
plugins_loaded
is definitely too early, that function only works for objects that are already registered. make sure when you hook oninit
that the priority is set such that it runs after everything is registered.