1

As mentioned in register_post_type() Codex page:

taxonomies
(array) (optional) An array of registered taxonomies like category or post_tag that will be used with this post type. This can be used in lieu of calling register_taxonomy_for_object_type() directly. Custom taxonomies still need to be registered with register_taxonomy().
Default: no taxonomies

In my Custom Post Type (product) I'm also assigning two Custom Taxonomies with register_taxonomy() apart from the register_post_type(), and they are working fine. But there's a parameter in register_post_type() called 'taxonomies' where it's said to mention all the taxonomies in an array, but even without this I'm achieving what it's meant to:

'taxonomies' => array( 'product_categories', 'product_tags' ),

So, I wonder what's the purpose of this?

3

To be really honest here, that is a useless parameter when used with custom taxonomies, as custom taxonomies are already registed to a custom post type when they are registered. Using the taxonomies parameter, you are re-registering a custom taxonomy to the custom post type

As stated by the codex, the taxonomies parameter is used to register build in taxonomies to custom post types, as build in taxonomies are registered to the build in post type post.

Just to close of, if you register a taxonomy to a post type, set the taxonomies parameter and use register_taxonomy_for_object_type(), you are doing the same job three times :-)

  • 1
    But makes perfect sense when registering CPT and adding native taxonomies to them. :) – Rarst Feb 23 '15 at 9:02
  • Can I point your attention to this part of Codex: Custom taxonomies still need to be registered with register_taxonomy(). Isn't it saying, Still Need? Isn't that mean, register once here and again there? It's just for clarification. I got your point, @Pieter. – Mayeenul Islam Feb 23 '15 at 9:15
  • @MayeenulIslam I think we lost each other here :-) Custom taxonomies has to be registered with register_taxonomy. When doing so, you do need to asign a taxonomy to a post type, that is the second parameter when registering a custom taxonomy. This registers a custom taxonomy to the specific post type which is set in the second parameter of register_taxonomy. This takes care of everything, so you don't need to assign the taxonomies parameter when registering your post type – Pieter Goosen Feb 23 '15 at 9:21

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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