我创建了一个自定义帖子类型'酒店'和自定义'分类',所以当管理员创建一个新酒店并保存它时,它会自动创建相关的自定义分类,但我不想在管理员酒店显示自定义元数据编辑页面所以我使用了WordPress函数 ,但没有任何反应。
我的自定义邮政编码
$Hotel_labels = array(
'name' => _x('Hotels', 'post type general name'),
'singular_name' => _x('Hotel', 'post type singular name'),
'add_new' => _x('Add New', 'Hotel'),
'add_new_item' => __('Add Hotel'),
'edit_item' => __('Edit Hotel'),
'new_item' => __('New Hotel'),
'all_items' => __('All Hotels'),
'view_item' => __('View Hotel'),
'search_items' => __('Search Hotel'),
'not_found' => __('No Hotel found'),
'not_found_in_trash' => __('No Hotel found in Trash'),
'parent_item_colon' => '',
'menu_name' => __('Hotel'),
);
$Hotel_args = array(
'labels' => $Hotel_labels,
'public' => true,
'rewrite' => array('slug' => 'Hotel'),
'publicly_queryable' => true,
'show_ui' => true,
'show_in_menu' => true,
'query_var' => true,
'rewrite' => true,
'capability_type' => 'post',
'has_archive' => true,
'hierarchical' => false,
'menu_position' => 100,
'supports' => array( 'title', 'editor', 'author', 'thumbnail' ),
'taxonomies' => array('hotel_facilities','package_hotel','post_tag')
);
register_post_type('Hotel',$Hotel_args);
$Package_labels = array(
'name' => _x( 'Package Hotels', 'taxonomy general name' ),
'singular_name' => _x( 'hotel', 'taxonomy singular name' ),
'search_items' => __( 'Search hotels' ),
'popular_items' => __( 'Popular hotels' ),
'all_items' => __( 'All hotels' ),
'parent_item' => null,
'parent_item_colon' => null,
'edit_item' => __( 'Edit hotel' ),
'update_item' => __( 'Update hotel' ),
'add_new_item' => __( 'Add New hotel' ),
'new_item_name' => __( 'New hotel Name' ),
'separate_items_with_commas' => __( 'Separate hotels with commas' ),
'add_or_remove_items' => __( 'Add or remove hotels' ),
'choose_from_most_used' => __( 'Choose from the most used hotels' ),
'menu_name' => __( 'Package Hotels' ),
);
register_taxonomy('package_hotel','package',array(
'hierarchical' => false,
'labels' => $Package_labels,
'show_ui' => true,
'update_count_callback' => '_update_post_term_count',
'query_var' => true,
'show_in_nav_menus' => false,
'rewrite' => array( 'slug' => 'hotels' ),
));
function my_remove_meta_boxes() {
remove_meta_box('tagsdiv_hotels', 'Hotel', 'side');
}
add_action( 'admin_menu', 'my_remove_meta_boxes' );
答案 0 :(得分:4)
自WordPress 3.8版本起,有一个meta_box_cb
argument available。只需在参数定义中将此参数更改为false
即可
$args = array(
'hierarchical' => false,
'public' => true,
'show_ui' => true,
'show_in_menu' => true,
'meta_box_cb' => false,
);
这将在您的自定义帖子类型下留下一个子菜单项,但会删除帖子编辑页面上的元框。
答案 1 :(得分:1)
更改元框ID
enter code here
function my_remove_meta_boxes(){remove_meta_box('package_hotel', '酒店','一边'); } add_action('admin_menu','my_remove_meta_boxes' );
答案 2 :(得分:0)
更改register_taxonomy()
:您已保留
'show_ui' => true,
将其更改为
'show_ui' => false,
此参数确定是否应显示用户界面以管理分类。由于您不想要它,您必须将其设置为false
。
答案 3 :(得分:0)
好的,现在Wordpress.org中给出的示例就像这样
`remove_meta_box($custom_taxonomy_slug.'div', $custom_post_type, 'side' );`
// $custom_taxonomy_slug is the slug of your taxonomy, e.g. 'genre' )
// $custom_post_type is the "slug" of your post type, e.g. 'movies' )
进一步指导在这样的函数中为metabox属性编写语法
remove_meta_box( 'submitdiv', 'custom_post_id', 'side' );
在我的例子中,自定义元数据属性的语法就是这样的
remove_meta_box('tagsdiv-package_hotel', 'hotel', 'side');
所以不要在末尾附加div而不是在begnning中附加tagsdiv_,例如: - tagsdiv_ $ your_custom_taxonomy_id