I’m working on a plugin that sets admin menu submenu pages on all different post types.
I need to be able to associate these new submenu pages with the corresponding post type of the top level menu item. Is this possible without having to rely on using $_GET
?
I see that $typenow
is used on edit.php
, but I cannot use that on my custom page, as it only returns NULL
.
So basically: How do I set appropriate/associate post type to a custom menu item.
UPDATED:
Here’s an image that hopefully describes a little bit better what I’m after.
As it is now, the Custom Item in the submenu is only available when Pages is active since otherwise $_GET
can’t fetch post_type
.
I’m using:
$post_type = esc_attr( $_GET['post_type'] );
$post_type_object = get_post_type_object( $post_type );
$title = $post_type_object->labels->name;
$page = add_submenu_page( 'edit.php?post_type=' . $post_type, $title, $title, 'edit_pages', 'order-' . $post_type, 'cmspo_menu_order_page' );
So I need a way to grab the appropriate post type that the custom item should be associated with, in this case it’s “page”, but there will be custom items under each custom post type that’s been registered with the capability_type
“page” rather than “post”.
You need the information about the current post type in your callback function that renders the submenu page output. And at this point there is a lot of information ready:
Result