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'm trying to add a custom link under my Post Type in my admin menu, which will link to Pending Posts. This code functions, but it instead makes a page (like I suppose the function should), but I just need a single link and there doens't seem to be a add_submenu_link function unfortunately. Is there a way to create a static link but place it in my post type submenu?

/** Add Pending Posts to WP Admin Menu **/
function add_custom_link() {
    add_submenu_page('edit.php?post_type=cpt_custom', '', 'Pending Posts', 5, __FILE__, 'sub_page_pending');
}
function sub_page_pending() {
  echo '<li><a href="edit.php?post_status=pending&post_type=cpt_custom">Pending Posts</a></li>';
}
add_action('admin_menu', 'add_custom_link');

I've tried to use a wp_redirect() but I get some errors telling me that the headers have already been set.

share|improve this question

1 Answer 1

up vote 1 down vote accepted

Insert the URL of the page as the $menu_slug argument. Also note that user levels are deprecated, you should pass a capability instead.

function add_custom_link() {
    add_submenu_page(
        'edit.php?post_type=cpt_custom',
        '',
        'Pending Posts',
        'edit_posts',
        'edit.php?post_type=cpt_custom&post_status=pending',
        ''
    );
}
add_action('admin_menu', 'add_custom_link');
share|improve this answer
    
The link kept going to my root, so I had to add a / at the front of my link, but it works! –  Howdy_McGee Feb 14 at 18:36

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.