In WordPress, the basic taxonomies, categories and tags, are only set up to be used on the default post type. If you want to add them to a custom post type you’ve created, you can do so by adding category
and/or post_tag
to the taxonomies
array element in the post type’s argument array.
Full example
<?php
// Register Movie Post Type
function register_movie_post_type()
{
$labels = array(
'name' => __('Movies', 'movie'),
'singular_name' => __('Movie', 'movie'),
'add_new' => __('New Movie', 'movie'),
'add_new_item' => __('Add New Movie', 'movie'),
'edit_item' => __('Edit Movie', 'movie'),
'new_item' => __('New Movie', 'movie'),
'view_item' => __('View Movie', 'movie'),
'search_items' => __('Search Movies', 'movie'),
'not_found' => __('No Movies Found', 'movie'),
'not_found_in_trash' => __('No Movies found in Trash', 'movie'),
);
$args = array(
'labels' => $labels,
'public' => true,
'publicly_queryable' => true,
'hierarchical' => false,
'supports' => array(
'title',
'editor',
'author',
'excerpt',
'custom-fields',
'thumbnail',
'revisions',
),
'taxonomies' => array('category', 'post_tag'),
'rewrite' => array('slug' => 'movie'),
'show_in_rest' => true,
'menu_icon' => 'dashicons-video-alt3',
);
register_post_type('movie', $args);
}
add_action('init', 'register_movie_post_type', 5);
Leave a Reply