Categories manage

Here is my code, which I have created in one of my project. Where, you have supposed to be register your CPT name as “products”. So, the created taxonomy visible to your CPT products only. Add these codes in your functions.php file. It’s simple no need of plugin.

/* Link products CPT to categories taxonomy
*/
add_action( 'init', 'add_category_taxonomy_to_products' );
function add_category_taxonomy_to_products() {
    register_taxonomy_for_object_type( 'category', 'products' ); // CPT as products
}

//Adding taxonomies for custom post type products
function create_products_taxonomies() {
    $labels = array(
        'name'              => _x( 'Products Categories', 'taxonomy general name' ),
        'singular_name'     => _x( 'Category', 'taxonomy singular name' ),
        'search_items'      => __( 'Search Categories' ),
        'all_items'         => __( 'All Categories' ),
        'parent_item'       => __( 'Parent Category' ),
        'parent_item_colon' => __( 'Parent Category:' ),
        'edit_item'         => __( 'Edit Category' ),
        'update_item'       => __( 'Update Category' ),
        'add_new_item'      => __( 'Add New Category' ),
        'new_item_name'     => __( 'New Category Name' ),
        'menu_name'         => __( 'Categories' ),
    );

    $args = array(
        'hierarchical'      => true, // Set this to 'false' for non-hierarchical taxonomy (like tags)
        'labels'            => $labels,
        'show_ui'           => true,
        'show_admin_column' => true,
        'query_var'         => true,
        'rewrite'           => array( 'slug' => 'categories' ),
    );

    register_taxonomy( 'products_categories', array( 'products' ), $args );
    flush_rewrite_rules() ;
}
add_action( 'init', 'create_products_taxonomies', 0 );