1

I'd like to have a submenu item in the admin section link directly to the edit form for a specific post ID, a custom post type at that.

Basically looking at using the add_submenu_page function to add the menu item http://codex.wordpress.org/Function_Reference/add_submenu_page which is easy.

Any ideas how to write a callback function to display the edit form for a specific post ID (which, in this case, happens to be a custom post type)?

1 Answer 1

2

You do not need a callback function at all. You could display (yet another) custom edit screen, but if the custom post type is set up correctly you should be able to reach it simply by pointing to http://yourdomain.com/wp-admin/post.php?post=9999&action=edit where 9999 is any post ID that corresponds to a post of said type.

Hence you can use post.php?post=9999&action=edit as the menu slug (see the codex page of add_menu_page for reference on parameters) with add_submenu_page and you're good to go:

add_submenu_page(
    'parent_slug',
    'Edit My Special Post', // page title, change to liking
    'Edit SP', // menu title, change to liking
    'edit_posts', // required capability, change to liking
    'post.php?post=9999&action=edit' // menu slug, change post ID
);

The last parameter, the callback function, you don't need at all.

2
  • That worked, except when I select that submenu option, while I'm taken to the correct edit form, the parent menu is closed and the menu item is not highlighted.
    – Uysrc
    Aug 14, 2012 at 15:20
  • @Uysrc & Johannes, this can be solved using jQuery and wrapping the page title above with a <span id="my-title" />, check this Answer.
    – brasofilo
    Jan 9, 2013 at 1:40

Your Answer

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

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