【发布时间】:2018-04-30 16:07:11
【问题描述】:
所以我完全遵循了 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,
)
);
【问题讨论】:
标签: wordpress custom-post-type custom-taxonomy