Skip to main content

Assigning a taxonomy to a post type

To assign a default or custom taxonomy to a custom post type in WordPress, you can use the 'taxonomies' argument when registering the post type.

Each post type has it's own "registration" file here: wp-content/mu-plugins/post-types-and-taxonomies/post-types

Here's an example of how to do this:

function register_my_custom_post_type() {
$args = array(
'public' => true,
'taxonomies' => array('category', 'post_tag'),
// other arguments go here
);
register_post_type('my-custom-post-type', $args);
}
add_action('init', 'register_my_custom_post_type');

In this example, the custom post type will be assigned the default WordPress categories and tags taxonomies. You can also specify a custom taxonomy by replacing one of the taxonomy names with the name of your custom taxonomy.