admin管理员组文章数量:1122832
I added a taxonomy and custom post type, but for some reason, my taxonomy isn't showing up when I add a new marker. I half expected it to be there like when selecting a category for a post, but it isn't. Any ideas what the issue might be?
function register_mm_post_types()
{
register_taxonomy('marker_types',
array('markers'),
array(
'labels' => array(
'name' => __('Marker type', 'moxxie'),
'singular_name' => __('Marker type', 'moxxie'),
'search_items' => __('Search marker types', 'moxxie'),
'all_items' => __('All marker types', 'moxxie'),
'parent_item' => __('Parent marker type', 'moxxie'),
'parent_item_colon' => __('Parent marker type:', 'moxxie'),
'edit_item' => __('Edit marker type', 'moxxie'),
'update_item' => __('Update marker type', 'moxxie'),
'add_new_item' => __('Add new marker type', 'moxxie'),
'new_item_name' => __('New marker type name', 'moxxie'),
'menu_name' => __('Marker types', 'moxxie')
),
'show_ui' => true,
'query_var' => true,
'hierarchical' => true,
'show_admin_column' => true,
'rewrite' => array('slug' => 'marker_types')
));
register_post_type('markers',
array( 'taxonomies' => array('marker_types'),
'labels' => array(
'name' => __('Map markers', 'moxxie'),
'singular_name' => __('Marker', 'moxxie'),
'add_new' => __('Add a new marker', 'moxxie'),
'edit_item' => __('Edit marker', 'moxxie'),
'new_item' => __('New marker', 'moxxie'),
'view_item' => __('View marker', 'moxxie'),
'search_items' => __('Search in maps', 'moxxie'),
'not_found' => __('No markers found', 'moxxie'),
'not_found_in_trash' => __('No markers found in trash', 'moxxie')
),
'has_archive' => true,
'show_in_rest' => true,
'hierarchical' => true,
'public' => true,
'menu_icon' => 'dashicons-location',
'capability_type' => 'post'
));
}
add_action('init', 'register_mm_post_types', 1);
As you can see, no taxonomy is shown. It would have to appear in the right-hand column, just like categories do in posts.
I added a taxonomy and custom post type, but for some reason, my taxonomy isn't showing up when I add a new marker. I half expected it to be there like when selecting a category for a post, but it isn't. Any ideas what the issue might be?
function register_mm_post_types()
{
register_taxonomy('marker_types',
array('markers'),
array(
'labels' => array(
'name' => __('Marker type', 'moxxie'),
'singular_name' => __('Marker type', 'moxxie'),
'search_items' => __('Search marker types', 'moxxie'),
'all_items' => __('All marker types', 'moxxie'),
'parent_item' => __('Parent marker type', 'moxxie'),
'parent_item_colon' => __('Parent marker type:', 'moxxie'),
'edit_item' => __('Edit marker type', 'moxxie'),
'update_item' => __('Update marker type', 'moxxie'),
'add_new_item' => __('Add new marker type', 'moxxie'),
'new_item_name' => __('New marker type name', 'moxxie'),
'menu_name' => __('Marker types', 'moxxie')
),
'show_ui' => true,
'query_var' => true,
'hierarchical' => true,
'show_admin_column' => true,
'rewrite' => array('slug' => 'marker_types')
));
register_post_type('markers',
array( 'taxonomies' => array('marker_types'),
'labels' => array(
'name' => __('Map markers', 'moxxie'),
'singular_name' => __('Marker', 'moxxie'),
'add_new' => __('Add a new marker', 'moxxie'),
'edit_item' => __('Edit marker', 'moxxie'),
'new_item' => __('New marker', 'moxxie'),
'view_item' => __('View marker', 'moxxie'),
'search_items' => __('Search in maps', 'moxxie'),
'not_found' => __('No markers found', 'moxxie'),
'not_found_in_trash' => __('No markers found in trash', 'moxxie')
),
'has_archive' => true,
'show_in_rest' => true,
'hierarchical' => true,
'public' => true,
'menu_icon' => 'dashicons-location',
'capability_type' => 'post'
));
}
add_action('init', 'register_mm_post_types', 1);
As you can see, no taxonomy is shown. It would have to appear in the right-hand column, just like categories do in posts.
Share Improve this question edited Feb 3, 2019 at 19:50 Michiel Standaert asked Feb 3, 2019 at 19:13 Michiel StandaertMichiel Standaert 3733 gold badges5 silver badges17 bronze badges 3- Under Screen Options tab, make sure your taxonomy is selected. – Milo Commented Feb 3, 2019 at 19:34
- No screen options in my "Add new"-page, in my custom posts overview page, I do have screen options and my taxonomy is checked there. – Michiel Standaert Commented Feb 3, 2019 at 19:51
- Added an image so you can see :) – Michiel Standaert Commented Feb 3, 2019 at 19:59
3 Answers
Reset to default 37The Gutenberg editor relies on the REST API, so both post types and taxonomies require the show_in_rest
parameter be set to true
when registering them. Your post type has this, but it's missing from your taxonomy.
Need to add in register_post_type
'has_archive' => true,
'show_in_rest' => true,
'taxonomies'=>array('marker_types'),
Like this. This work for me.
For anyone using Custom Post Types UI's Taxonomies https://wordpress.org/plugins/custom-post-type-ui/ , the "Show in REST API" must be checked on CPT UI -> Add/Edit Taxonomies. It's probably the equivalent of what @Milo states setting show_in_rest
= true
.
本文标签: Custom taxonomy not showing up when adding a new custom post type
版权声明:本文标题:Custom taxonomy not showing up when adding a new custom post type 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1736307087a1933189.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论