Skip to main content
Added note on custom taxonomies
Source Link
Simon
  • 1.2k
  • 7
  • 10

There are essentially two ways to do this.

The first is to supply the taxonomies keyword in the register_post_type arguments array, like so:

register_post_type('my_type', array(
    ...
    'taxonomies' => array('category', 'post_tag'),
    ...
));

The other is to register your post type and set up its taxonomies at a later point:

register_taxonomy_for_object_type( 'category', 'my_type' );
register_taxonomy_for_object_type( 'post_tag', 'my_type' );

UPDATE: Likely you will want some of these taxonomies to be exclusive to your post type. First, taxonomies exists across all post types, that's their strength. If however, you want to be able to add tags that are exclusive to your custom post type you will have to register a custom taxonomy as well.

register_taxonomy('my_tax', 'my_type'); // You will have to run this one time for each post type you wish to use

The above should do fine, but check out the register_taxonomy documentation as there are quite a few arguments you can supply to affect its behavior.

There are essentially two ways to do this.

The first is to supply the taxonomies keyword in the register_post_type arguments array, like so:

register_post_type('my_type', array(
    ...
    'taxonomies' => array('category', 'post_tag'),
    ...
));

The other is to register your post type and set up its taxonomies at a later point:

register_taxonomy_for_object_type( 'category', 'my_type' );
register_taxonomy_for_object_type( 'post_tag', 'my_type' );

There are essentially two ways to do this.

The first is to supply the taxonomies keyword in the register_post_type arguments array, like so:

register_post_type('my_type', array(
    ...
    'taxonomies' => array('category', 'post_tag'),
    ...
));

The other is to register your post type and set up its taxonomies at a later point:

register_taxonomy_for_object_type( 'category', 'my_type' );
register_taxonomy_for_object_type( 'post_tag', 'my_type' );

UPDATE: Likely you will want some of these taxonomies to be exclusive to your post type. First, taxonomies exists across all post types, that's their strength. If however, you want to be able to add tags that are exclusive to your custom post type you will have to register a custom taxonomy as well.

register_taxonomy('my_tax', 'my_type'); // You will have to run this one time for each post type you wish to use

The above should do fine, but check out the register_taxonomy documentation as there are quite a few arguments you can supply to affect its behavior.

edited body
Source Link
Simon
  • 1.2k
  • 7
  • 10

There are essentially two ways to do this:.

The first is to supply the taxonomies keyword in the register_post_type arguments array, like so:

register_post_type('my_type', array(
    ...
    'taxonomies' => array('category', 'post_tag'),
    ...
));

The other is to register your post type and set up its taxonomies at a later point:

register_taxonomy_for_object_type( 'category', 'my_type' );
register_taxonomy_for_object_type( 'post_tag', 'my_type' );

There are essentially two ways to do this:

The first is to supply the taxonomies keyword in the register_post_type arguments array, like so:

register_post_type('my_type', array(
    ...
    'taxonomies' => array('category', 'post_tag'),
    ...
));

The other is to register your post type and set up its taxonomies at a later point:

register_taxonomy_for_object_type( 'category', 'my_type' );
register_taxonomy_for_object_type( 'post_tag', 'my_type' );

There are essentially two ways to do this.

The first is to supply the taxonomies keyword in the register_post_type arguments array, like so:

register_post_type('my_type', array(
    ...
    'taxonomies' => array('category', 'post_tag'),
    ...
));

The other is to register your post type and set up its taxonomies at a later point:

register_taxonomy_for_object_type( 'category', 'my_type' );
register_taxonomy_for_object_type( 'post_tag', 'my_type' );
Source Link
Simon
  • 1.2k
  • 7
  • 10

There are essentially two ways to do this:

The first is to supply the taxonomies keyword in the register_post_type arguments array, like so:

register_post_type('my_type', array(
    ...
    'taxonomies' => array('category', 'post_tag'),
    ...
));

The other is to register your post type and set up its taxonomies at a later point:

register_taxonomy_for_object_type( 'category', 'my_type' );
register_taxonomy_for_object_type( 'post_tag', 'my_type' );