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 on init that the priority is set such that it runs after everything is registered. – Milo Feb 18 '15 at 23:56
up vote 3 down vote accepted

plugins_loaded will definitely be too soon as it is standard practice to use init to set up custom post types and taxonomies.

That being said, if init is not working for you it could well be that whoever is creating them is creating them either at a later init ... or you are using the same init priority and your function is firing before theirs.

try changing you action call to

add_action('init', 'cptpages_register_taxonomy', 50);

Or even 99 ... and see if that does the trick.

Otherwise, search their code to see how / when they are registering them and act accordingly.

  • That was the ticket - tx! (and Milo as well) – user67763 Feb 19 '15 at 8:58

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.