Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

Case:

I register_post_type() 3 different CPTs1)

Example: 3 post types named party, event, location. The other needed arguments in the array are left out.

register_post_type(
     'party'
    ,array( 
        'show_in_menu' // true (for main) or "edit.php?post_type=party (for subentries)
     )
);
  • Then I set the 'show_in_menu' argument for the first CPT item (a.k.a "party") to true
  • The other items get set 'show_in_menu' to 'edit.php?post_type=party

Result:

enter image description here

What's the point with this? What I expected was that I get "Add New" menu items for all of them, not only for the main CPT.

How would I do set the arguments to not only get list views, but single new/edit screens as well?

Notes:

I know, that I got an Add New button in the list view on top next to the title, but I want to know how I could add these links to the admin menu items.

I also know that I can work around with

add_submenu_page(
     "edit.php?post_type=party"
    ,"Add New"
    ,"Add New"
    ,"post-new.php?post_type=party"
);

but I'm not interested in the work around. I want to know how this is thought to work out of the box.

1) CPT = short for custom post type

share|improve this question
    
As for as I can tell they simply don't work like this, even using submenu_page can have ordering problems, I have had to unset them all and add them in the order I wanted. –  Wyck Nov 18 '11 at 5:21
    
@Wyck Would you mind adding a snippet as answer? It seems like I have to be satisfied with the massive set of work arounds, like I already had to find out with separators. –  kaiser Nov 18 '11 at 5:23

1 Answer 1

up vote 1 down vote accepted

Customizing the menu this way is as for as I can tell, not very friendly. What I had to do recently was custom built the submenu item using remove_submenu_page for all the sub menu items and then add them in the order I wanted using add_submenu_page.

A simple example

 //this was first sub-menu item I did not want it #1
 remove_submenu_page( 'edit.php?post_type=test', 'edit.php?post_type=test' );

 // add the actual sub-menu item I wanted as #1
 add_submenu_page('edit.php?post_type=hello','Hello', 'Hello', 'manage_options', 'my_hello', 'my_hello_options');

//re-add the orginal #1 item removed above so it is now the #2 item
 add_submenu_page('edit.php?post_type=test','Edit Test', 'Edit Test', 'manage_options', 'edit.php?post_type=test');

Edit: If you plan on using the menu_order filter, it's pretty simple to get the filter working: Just add this line before it. Else it would skip the menu_order filter: add_filter( 'custom_menu_order', '__return_true' );.

share|improve this answer
    
So ordering happens simply by adding it step by step? –  kaiser Nov 18 '11 at 7:25
    
I think so, not 100% sure, the alternative would be something crazy like this, wordpress.stackexchange.com/questions/28861/… –  Wyck Nov 18 '11 at 15:25
    
Ok, seems to still crazy removing and adding, but as there's no way around this: Thanks a lot! –  kaiser Nov 22 '11 at 14:24

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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