0

I've created custom post type called 'video' and added category support. The problem is when i go to category of custom post type, it shows normal post's categories as well.

I wanna seperate them How can i fix this?


My custom-post-type code:

add_action( 'init', 'register_cpt_video' );

function register_cpt_video() {

    $labels = array(
        'name' => __( 'Videolar', 'video' ),
        'singular_name' => __( 'Video', 'video' ),
        'add_new' => __( 'Yeni Video Ekle', 'video' ),
        'add_new_item' => __( 'Yeni Video Ekle', 'video' ),
        'edit_item' => __( 'Video Düzenle', 'video' ),
        'new_item' => __( 'Yeni Video', 'video' ),
        'view_item' => __( 'Video Görüntüle', 'video' ),
        'search_items' => __( 'Video Arama', 'video' ),
        'not_found' => __( 'Herhangi bir video bulunamadı', 'video' ),
        'not_found_in_trash' => __( 'Herhangi bir video bulunmadı', 'video' ),
        'parent_item_colon' => __( 'Ebeveyn Video', 'video' ),
        'menu_name' => __( 'Videolar', 'video' ),
    );

    $args = array(
        'labels' => $labels,
        'hierarchical' => false,
        'description' => 'Video Galeri içeriklerinizi buradan giriniz.',
        'supports' => array( 'title', 'editor', 'excerpt', 'author', 'thumbnail', 'trackbacks', 'custom-fields', 'comments', 'revisions', 'page-attributes' ),
        'taxonomies' => array( 'category', 'post_tag' ),
        'public' => true,
        'show_ui' => true,
        'show_in_menu' => true,
        'menu_position' => 5,
        'menu_icon' => 'dashicons-video-alt2',
        'show_in_nav_menus' => true,
        'publicly_queryable' => true,
        'exclude_from_search' => false,
        'has_archive' => false,
        'query_var' => true,
        'can_export' => true,
        'rewrite' => true,
        'capability_type' => 'post'
    );

    register_post_type( 'video', $args );
}
1
  • Create custom taxonomy for the custom post type
    – bravokeyl
    Commented May 7, 2016 at 16:23

1 Answer 1

2

You've added the following line to arguments: 'taxonomies' => array( 'category', 'post_tag' ),. It will register the same categories and tags to video post type which you're using with default posts.

First things first: remove line 'taxonomies' => array( 'category', 'post_tag' ),

In order to have a new "exclusive" taxonomy only for video post type, you'll need to register a new taxonomy. This should go to same .php file where you're registering your new post type if it's exclusive to only video post type. This is not mandatory but it's better for future maintenance.


I've added few arguments that I usually specify. See all the possible args here. Read the whole document to get what you actually need. Some of these arguments alter the behaviour a lot.

// Video categories
add_action( 'init', 'register_taxonomy_video_category', 0 );

function register_taxonomy_video_category() {

    $labels = array(
        // See list of labels in docs I linked above (bold and blue "here")     
    );


    $args = array(  

        // Custom labels? Remove them all to get "default"
        'labels'              => $labels,
        // Does these have child-parent relationships?
        'hierarchical'        => true,
        // Translatable pretty slugs?
        'rewrite'             => array( 'slug' => __( 'video-category', 'video' ) ),
        // Generate a default UI for managing this taxonomy?
        'show_ui'             => true,
        // Allow automatic creation of taxonomy columns on associated post-types table?
        'show_admin_column'   => true,
        // Show in quick edit panel?
        'show_in_quick_edit'  => false
        )  
    );

    // "video-category" is the name of the taxonomy
    // "video" is the post type you want it to use with
    register_taxonomy( 'video-category', 'video', $args );
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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