admin管理员组

文章数量:1419666

In wordpress 5.22 , After creating a custom post type like:

function create_products_cpt(){
    register_post_type( 'product',
        array(
            'labels' => $labels,
            'public' => true,
            'supports' => array(
                'title',
                'editor',
                'thumbnail',
                'custom-fields'
            ),
            'taxonomies'=>['product-category'],
            'register_meta_box_cb' => 'register_metaboxes',
            'show_in_rest' => true
        )
    );

    register_taxonomy('product-category','product',array(
        'hierarchical'=>true,
        'label'=>'product categories'
    ));

}
add_action( 'init', 'create_products_cpt' );

I am able to create post types and categories inside the taxonomy from the dashboard, but it is impossible to mark a specific post of that post type as belonging to any of the categories, since the selector just doesn't appear. I double-checked on an older version of wordpress (4.89) and it does work as intended, selector and all. What could be the issue here?

In wordpress 5.22 , After creating a custom post type like:

function create_products_cpt(){
    register_post_type( 'product',
        array(
            'labels' => $labels,
            'public' => true,
            'supports' => array(
                'title',
                'editor',
                'thumbnail',
                'custom-fields'
            ),
            'taxonomies'=>['product-category'],
            'register_meta_box_cb' => 'register_metaboxes',
            'show_in_rest' => true
        )
    );

    register_taxonomy('product-category','product',array(
        'hierarchical'=>true,
        'label'=>'product categories'
    ));

}
add_action( 'init', 'create_products_cpt' );

I am able to create post types and categories inside the taxonomy from the dashboard, but it is impossible to mark a specific post of that post type as belonging to any of the categories, since the selector just doesn't appear. I double-checked on an older version of wordpress (4.89) and it does work as intended, selector and all. What could be the issue here?

Share Improve this question asked Jul 25, 2019 at 0:14 SessionCookieMonsterSessionCookieMonster 132 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 0

I've pasted your code in Twenty Nineteen and it works as expected with Classic Editor ( and I'm sure it will work pre-Block Editor also ). Your taxonomy will not show up in the Block Editor unless you specify to display that taxonomy in rest as you've done with your post type:

register_taxonomy( 'product-category', 'product', array(
    'hierarchical'=>true,
    'label'=>'product categories',
    'show_in_rest' => true
) );

Once you enable REST it will become available in the Block Editor.

本文标签: Taxonomies don39t show up on in the dashboard page for a custom post type in wordpress 522