$args = array(
'label' => __( 'Eventr', 'dnp_theme' ),
'description' => __( 'What clients say ', 'dnp_theme' ),
'labels' => $labels,
'supports' => array( 'title', 'editor', 'thumbnail'),
'taxonomies' => array( 'Eventr', 'product_cat'),
'hierarchical' => false,
'public' => true,
'show_ui' => true,
'show_in_menu' => true,
'show_in_nav_menus' => false,
'show_in_admin_bar' => true,
'menu_position' => 10,
'menu_icon' => 'dashicons-images-alt2',
'can_export' => true,
'has_archive' => false,
'exclude_from_search' => false,
'publicly_queryable' => true,
'capability_type' => 'post',
);
register_post_type( 'Eventr', $args );
This is My Code Using to Get Woocommerce Product Categories in my Custom Post type.
In Taxonomies i have add woocommerce product category taxonomies “product_cat” but it not to show on admin panel.
Help me to know How to add WooCommerce Product Categories in Custom Post Type Admin Menu.
I was having the same issue, and I found that registering the taxonomy afterwards seemed to work. So in your functions after registering the custom post type, add something like this, where
custom_post_type
key is the key you registered:To anyone having this issue in 2020 and with the Gutenberg editor:
Step 1:
Register the taxonomy either using
register_taxonomy_for_object_type
or by setting it in the post type registration arguments using thetaxonomies
field (as in the other answers and the question).Step 2:
Include the taxonomy in the REST API and make it available in the block editor by setting
show_in_rest
totrue
.For
product_cat
, this means to change this setting using thewoocommerce_taxonomy_args_product_cat
filter.Use the function
register_taxonomy_for_object_type()
called oninit
, but make sure the timing is right so that this call fires after your CPT registration. Notice the use of 99 as the priority setting in this case.