I have registered a custom taxonomy for my custom post type:
$labels = array(
...labels here...
);
$args = array(
'label' => __('Categories', $this->text_domain),
'labels' => $labels,
'public' => true,
'show_ui' => true,
'show_in_nav_menus' => true,
'show_admin_column' => true,
'hierarchical' => true,
'query_var' => true,
'rewrite' => array('slug' => 'virtual-product-category'),
);
register_taxonomy('virtual_product_cat', array('virtual_product'), $args);
Works as expected – I can pick a custom category for my custom post.
Then I added it to a custom menu:
add_submenu_page(
'virtual',
__('Virtual Product Categories', $this->text_domain),
__('Categories', $this->text_domain),
'edit_products',
'edit-tags.php?post_type=virtual_product&taxonomy=virtual_product_cat'
);
It shows up:
When I click on it (the “Categories” link), taxonomy editing page loads fine, however, parent menu is displayed collapsed and the child (“Categories”) is not highlighted:
Custom post type (linke “Virtual Products”), on the other hand, works as expected (see the first picture).
I could do some hacks / workarounds, play with JS/CSS to make it highlighted but I think I am missing something here..
So, how do I make custom taxonomy menu link under custom menu work properly?
Thanks!
Ok, for all folks who run into the same issue..
What you are doing is:
add_menu_page
Do this instead:
'show_in_menu'
argument – this will create a menu for you. You can control where it appears by setting a'menu_position'
under the same args array.add_submenu_page
, use'edit.php?post_type=%%post_type_name%%'
as a parent slug (the first param).Simply – don’t do the other way around 🙂
Thanks to Obmerk Kronen and stink who tried to help. Appreciate this.
I was looking for the same thing, but I did not want the to use the Custom Post Type as the main menu.
I eventually found this link on the WP.org support forum http://wordpress.org/support/topic/moving-taxonomy-ui-to-another-main-menu
Code outlined below.
You could use this as a template or just use this taxonomy generator like I did.
@sPaul what you referenced in your answer works for custom post types but not for taxonomies. There isn’t a
'menu_position'
arg for custom taxonomies. What you had done in your question will work fine to create the link under your menu:But to get it to show the correct styles you’ll need to add some JS to add / remove classes. Here’s how (modified from https://wordpress.stackexchange.com/a/225228/80088):