1
votes

So I followed the JointsWP custom post type templates exactly. But in the wordpress admin, in the menu my Categories and Tags are not quite right. I need to remove the Categories and Tags menu items that belong to Posts.

Here's the current state of my wordpress admin menu for the CPT....

Listings (my CPT, exactly as I want)
- All Listings (working)
- Add New (working)
- Categories (I need this gone! this is actually connected to "Posts" categories for regular blog posts)
- Tags (I need this gone! this is actually connected to "Posts" tags for regular blog posts)
- Listings Categories (working)
- Listings Tags (working)

I have already tried the hack fix in my functions.php:

// Removing some menu items
function remove_menus() {
remove_menu_page( 'edit-tags.php?taxonomy=category&post_type=listings' );
remove_menu_page( 'edit-tags.php?taxonomy=post_tag&post_type=listings' );
}
add_action( 'admin_menu', 'remove_menus' );

Here's a copy of my functions for the CPT, it's basically just a copy of what came with JointsWP, that I edited for my own purposes

function custom_post_example() { 
register_post_type( 'listings', 
    array('labels' => array(
        'name' => __('Listings', 'jointswp'), 
        'singular_name' => __('Listing', 'jointswp'), 
        'all_items' => __('All Listings', 'jointswp'), 
        'add_new' => __('Add New', 'jointswp'), 
        'add_new_item' => __('Add New Listing', 'jointswp'),
        'edit' => __( 'Edit', 'jointswp' ), 
        'edit_item' => __('Edit Listing', 'jointswp'), 
        'new_item' => __('New Listing', 'jointswp'),
        'view_item' => __('View Listing', 'jointswp'), 
        'search_items' => __('Search Listings', 'jointswp'), 
        'not_found' =>  __('Nothing found in the Database.', 'jointswp'),
        'not_found_in_trash' => __('Nothing found in Trash', 'jointswp'), 
        'parent_item_colon' => ''
        ), 

        'description' => __( 'This is the Listing custom post type', 'jointswp' ), 
        'public' => true,
        'publicly_queryable' => true,
        'exclude_from_search' => false,
        'show_ui' => true,
        'query_var' => true,
        'menu_position' => 8, 
        'menu_icon' => 'dashicons-building', 
        'rewrite'   => array( 'slug' => 'listings', 'with_front' => false ), 
        'has_archive' => 'listings', 
        'capability_type' => 'post',
        'hierarchical' => false,
        'supports' => array( 'title', 'editor', 'author', 'thumbnail', 'custom-fields', 'revisions', 'sticky')

    )
); 

register_taxonomy_for_object_type('category', 'listings');
register_taxonomy_for_object_type('post_tag', 'listings');
} 
add_action( 'init', 'custom_post_example');

register_taxonomy( 'listing_cat', 
    array('listings'), 
    array('hierarchical' => true,         
        'labels' => array(
            'name' => __( 'Listing Categories', 'jointswp' ),
            'singular_name' => __( 'Listing Category', 'jointswp' ),
            'search_items' =>  __( 'Search Listing Categories', 'jointswp' ),
            'all_items' => __( 'All Listing Categories', 'jointswp' ),
            'parent_item' => __( 'Parent Listing Category', 'jointswp' ),
            'parent_item_colon' => __( 'Parent Listing Category:', 'jointswp' ),
            'edit_item' => __( 'Edit Listing Category', 'jointswp' ),
            'update_item' => __( 'Update Listing Category', 'jointswp' ), 
            'add_new_item' => __( 'Add New Listing Category', 'jointswp' ),
            'new_item_name' => __( 'New Listing Category Name', 'jointswp' ) 
        ),
        'show_admin_column' => true, 
        'show_ui' => true,
        'query_var' => true,
        'rewrite' => array( 'slug' => 'listing' ),
    )
);   

register_taxonomy( 'listing_tag', 
    array('listings'), 
    array('hierarchical' => false,            
        'labels' => array(
            'name' => __( 'Listing Tags', 'jointswp' ), 
            'singular_name' => __( 'Listing Tag', 'jointswp' ),
            'search_items' =>  __( 'Search Listing Tags', 'jointswp' ),
            'all_items' => __( 'All Listing Tags', 'jointswp' ), 
            'parent_item' => __( 'Parent Listing Tag', 'jointswp' ),
            'parent_item_colon' => __( 'Parent Listing Tag:', 'jointswp' ),
            'edit_item' => __( 'Edit Listing Tag', 'jointswp' ), 
            'update_item' => __( 'Update Listing Tag', 'jointswp' ), 
            'add_new_item' => __( 'Add New Listing Tag', 'jointswp' ),
            'new_item_name' => __( 'New Listing Tag Name', 'jointswp' )
        ),
        'show_admin_column' => true,
        'show_ui' => true,
        'query_var' => true,
    )
); 
2

2 Answers

1
votes

You might have passed following parameter while registering your custom post type:

'taxonomies'            => array( 'category', 'post_tag' ),

This line will associate default category and tags taxonomy to your custom post type. If you don't want in your custom post type, then you need to pass empty array in that parameter as following:

'taxonomies'            => array( ),

So here is the array of arguments to be passed while registering custom post type:

$args = array(
        'label'                 => __( '[name of CPT]', 'text_domain' ),
        'description'           => __( 'Post Type Description', 'text_domain' ),
        'labels'                => $labels, // array of labels
        'supports'              => array( ),
        'taxonomies'            => array( ),
        'hierarchical'          => false,
        'public'                => true,
        'show_ui'               => true,
        'show_in_menu'          => true,
        'menu_position'         => 5,
        'show_in_admin_bar'     => true,
        'show_in_nav_menus'     => true,
        'can_export'            => true,
        'has_archive'           => true,        
        'exclude_from_search'   => false,
        'publicly_queryable'    => true,
        'capability_type'       => 'page',
    );
    register_post_type( [custom post type name], $args );
0
votes

removing these, solved the issue.

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