0
votes

I created a custom post type whic works perfectly fine. Now I want to have a submenu entry within the CPT which list all posts with the status pending, somthing like this:

  • wp-admin/edit.php?post_type=&post_status=pending

I added a submenue, which then calls a page like:

  • wp-admin/edit.php?post_type=&page=XYZ

There should be an easy way of doing this, but I didn't find it ;-(

Here ist what I want in detail:

Admin Menu
New CPT <br> -> wp-admin/edit.php?post_type=<CPT>
- Submenue   -> wp-admin/edit.php?post_type=<CPT>&post_status=pending

Thanks for your help!

1

1 Answers

0
votes

I found it myself and I also integrated a notification bubble of how many post are in there of a specific type:

// Add SubMenu
add_action('admin_menu', 'register_my_custom_submenu_page');

function register_my_custom_submenu_page() {
  $count_posts = wp_count_posts('<custom post type name>'); 
  $draft_posts = $count_posts-><status i.e. Pending>;
  $pageName = "<Name of submenu>";
  $pageName .= " <span class='update-plugins count-1'><span class='update-count'>$draft_posts</span></span>";
  add_submenu_page( 'edit.php?post_type=<custom post type name>', '<Title>', $pageName, '<capability>', 'edit.php?post_type=<custom post type name>&post_status=<status i.e. Pending>' ); 
  }