However, for my taxonomy the links do not have the post_type argument
Yes, and it’s because that argument does not exist in your submenu slug or relative URL (the 5th parameter for add_submenu_page()
), therefore WordPress would not know that you’re targeting your post type, and WordPress also would not add that argument to the links for filtering posts by your taxonomy at wp-admin/edit.php
.
Remember that taxonomies can be attached to two or more post types, hence you should always include the post_type
argument in your submenu link, even if your taxonomy will only ever going to have one post type. Because when that argument is missing or not specified, WordPress will not default to using the only post type attached to a taxonomy having just one post type attached.
So make sure to include that argument, just like WordPress does it when show_in_menu
is not specified or is set to true
:
add_submenu_page(
'TDLRM',
'Ingredients',
'Ingredients',
'edit_posts',
'edit-tags.php?taxonomy=tdlrm_ingredients&post_type=tdlrm_store_item',
''
);
Additional Notes
-
As I commented, you could actually set
show_in_menu
to the slug of a top-level menu page added usingadd_menu_page()
, but you would want to use 9 or lower as the action’s priority as inadd_action( 'admin_menu', 'your_function', 9 )
. More details here (see the 1st note)And if that’s not preferred (e.g. because you want another submenu item as the first one, but you need to use 10 or more as the action’s priority), then just use
'show_in_menu' => false
and manually calladd_submenu_page()
to add your post type as a submenu of your admin menu. 🙂