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.

I am adding a large number of custom post types and taxonomies so it is often visually clearer if I DO NOT have them all added to the admin menu's top level. Instead I would prefer to add them under an appropriate sub-menu. I have done that without too much effort with this two step approach:

  1. Hiding CPT using the 'show_ui' property when registering the CPT
  2. Adding them back in using the add_submenu_page() call

For instance, here's an example of the the add_submenu_page call for a CPT called "companies":

add_submenu_page (LG_ADMIN_MENU,"Companies","Companies","manage_options",'edit.php?post_type=companies');

By taking these two steps I can now view the CPT, I can modify existing attributes, I can even delete a record but what I can't do is add a record. When I click on the "Add New" button it comes back with a white screen that only says "Invalid post type".

Now if I simply turn on the normal top-level menu (leaving all other settings alone), I get the menu now showing up both as a submenu (from my add_submenu_page call) and as a top-level menu (because I've turned that back on with "show_ui". I can then add new items with no problem.

share|improve this question
    
could you edit your post so that there is a clear question? –  Stephen Nov 6 '12 at 21:57
add comment

2 Answers

up vote 1 down vote accepted

Have you tried show_in_menu instead?

register_post_type( 'companies', array(
     'show_in_menu' => LG_ADMIN_MENU,
     'show_ui' => true,
     '...',
));
share|improve this answer
    
Ummm no. Seems like a really good idea on the surface. Let me try that now. –  ken Nov 7 '12 at 11:09
    
Ok, this seems to work. Great stuff! –  ken Nov 7 '12 at 11:30
    
One small remaining problem ... in most cases I see that the taxonomies attached to a CPT (who is in my own menu) follows the CPT to the new menu. In one case though, they just disappear. Any ideas? –  ken Nov 7 '12 at 11:31
    
Can you expand on "in one case"? –  TheDeadMedic Nov 7 '12 at 11:47
    
The short version is "i'm an idiot". The slightly longer version is that you need to explicitly register the taxonomies into the menu with the add_submenu_page() which I done for the working ones but forgot I needed that for the others. –  ken Nov 7 '12 at 12:14
add comment

It isn't entirely clear which "add new" button you mean, but if you are talking about the "Add New" button that appears at the top of your "edit.php?post_type=" page (at least ordinarily) it is possible to alter that URL but it is 'hack-ie'. I think that is what you need to do though.

function reset_new_link() {
    global $post_new_file;
    $post_new_file = admin_url('whatever');
}
add_action('admin_head','reset_new_link');

Take this code as a kind of proof of concept. You don't want to use it as is because it will change that link across the whole of the backend. You need to add conditions for when to change the link and when not to. Most of the information you need is probably in the $post_type_object object. Add global $post_type_object; var_dump($post_type_object); to see what you have to work with.

share|improve this answer
add comment

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.