Is it possible to add same category for multiple custom post type?
for example,
coupon post type - deal post type - both should share common cateogires, such as health, travel etc.
But, when we create new post type, looks like, we need to provide custom category also.
Do you have any clue how to create custom post types without custom categories?
Yes, custom-post-types can have multiple taxonomies ( categories, tags, custom ).
Yes, you can have a custom post type without a taxonomy.
Adding categories to custom post types is done like so:
'taxonomies' => [ 'category' ], // <--- add this (or use 'post_tag' to add tags to the CPT)
'public' => true,
'show_ui' => true,
'exclude_from_search' => true,
'hierarchical' => true,
'supports' => [
'title',
'editor',
'thumbnail',
],
'query_var' => true,
If you want to add a custom taxonomy to multiple post types, you can do this:
function people_init() {
// create a new taxonomy
register_taxonomy(
'people', [ // <-- 'people' taxo added to posts, pages, & custom_post_type
'post',
'page',
'custom_post_type',
],
array(
'label' => __( 'People' ),
'rewrite' => [
'slug' => 'person',
],
'capabilities' => [
'assign_terms' => 'edit_guides',
'edit_terms' => 'publish_guides',
]
)
);
}
add_action( 'init', 'people_init' );
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With