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.


Here's an image that hopefully describes a little bit better what I'm after. http://i.imgur.com/4q4Dy.jpg

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".


1 Answer 1


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:

add_action( 'admin_menu', 'wpse_60730_demo_submenu' );

 * Register sub menu pages.
 * Note that get_current_screen() is still NULL now.
 * @wp-hook admin_menu
 * @return void
function wpse_60730_demo_submenu()
    // get public post types
    $post_types = get_post_types( array ( 'public' => TRUE ) );

    foreach ( $post_types as $post_type )
            "Extra $post_type", // this should be made translatable
            "Extra $post_type", // this too
 * Render the sub menu page output.
 * All information is set now.
 * @return void
function wpse_60730_demo_callback()
    $screen = get_current_screen();
    global $typenow, $parent_file;
    print "<pre>get_current_screen()\n" . htmlspecialchars( print_r( $screen, TRUE ) ) . '</pre><hr>';
    print "<pre>\$typenow: " . htmlspecialchars( print_r( $typenow, TRUE ) ) . '</pre><hr>';
    print "<pre>\$parent_file: " . htmlspecialchars( print_r( $parent_file, TRUE ) ) . '</pre>';


enter image description here

  • Solved the problem I was having, changed from edit_{$post_type}s to edit_pages and it all worked out.
    – INT
    Commented Aug 8, 2012 at 14:46

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.