Aftab
Aftab

Reputation: 417

How to display custom post type in a submenu?

I am adding a submenu named as "Articles" using add_submenu_page() under a custom menu. I want to display the custom post type="page_article" in this "Articles" submenu.

Whenever I click on Articles submenu , it should redirect me to "edit.php?post_type="page_article".

I have tried with wp_redirect in callback function of add_submenu_page, but I am not getting.

Thanks

Upvotes: 5

Views: 8426

Answers (1)

Shashank Singh
Shashank Singh

Reputation: 1300

Probably i think you want to add a custom type post as sub-menu in WordPress dashboard. You can do.

 add_action( 'admin_menu', 'my_plugin_menu' );
 function my_plugin_menu(){
   add_menu_page('Page title', 'Top-level menu title', 'manage_options',  'my-top-level-handle', 'my_menu_function');
   add_submenu_page( 'my-top-level-handle', 'Custom Post Type Admin', 'Articles', 'manage_options','edit.php?post_type=page_article');
 }

Don't forget to add below code while registering a custom type post

 'show_in_menu' => 'edit.php?post_type=page_article'

Upvotes: 13

Related Questions