Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

like image 437
Aftab Avatar asked May 13 '15 10:05

Aftab


1 Answers

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'
like image 61
Shashank Singh Avatar answered Oct 19 '22 23:10

Shashank Singh