所以我完全遵循了JointsWP自定义帖子类型模板。但是在wordpress管理员中,在菜单中我的分类和标签并不完全正确。我需要删除属于帖子的类别和标签菜单项。
这是CPT的wordpress管理菜单的当前状态....
列表(我的CPT,完全按照我的意愿)
- 所有列表(工作)
- 添加新(工作)
- 类别(我需要这个消失!这实际上是连接到常规博客帖子的“帖子”类别)
- 标签(我需要这个!这实际上是连接到常规博客帖子的“帖子”标签)
- 商品类别(工作)
- 列表标签(工作)
我已经在我的functions.php中试过了hack修复:
// 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' );
这是我的CPT功能的副本,它基本上只是JointsWP附带的副本,我为自己的目的编辑了
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,
)
);
答案 0 :(得分:1)
注册自定义帖子类型时,您可能已经传递了以下参数:
'taxonomies' => array( 'category', 'post_tag' ),
此行会将默认类别和代码分类与您的自定义帖子类型相关联。如果您不想要自定义帖子类型,则需要在该参数中传递空数组,如下所示:
'taxonomies' => array( ),
所以这里是注册自定义帖子类型时要传递的参数数组:
$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 );
答案 1 :(得分:0)
删除这些,解决了这个问题。
register_taxonomy_for_object_type('category', 'listings');
register_taxonomy_for_object_type('post_tag', 'listings');