Adding My posts sub menu for posts section in wordpress

Let me explain the situation. Suppose you have contributor access to wordpress. If you go to posts page in admin panel that list all posts   and here you are not author of all posts.  you will see the url like

edit.php?post_type=post&all_posts=1

and All( total post number here). There will be another menu named Mine(Current user post number). All link is default. So we can make nother submenu of posts in admin section for Mine link directly. Let me show you the few lines code.

add_action('admin_menu', 'manchu_myposts');
function manchu_myposts()
{
    if (function_exists('add_submenu_page'))
    {
		//$parent, $page_title, $menu_title, $access_level, $file, $function = ''
		add_submenu_page('edit.php','My Posts','My posts', 1, 'edit.php?post_type=post&author='.get_current_user_id());
    }
}

You can copy-paste above code in your theme functions.php file and it will show a new sub menu in posts ectin as My posts. Multi user blog users can get easily link for his/her posts.
myposts
it’s just a easy way to make personal posts link for any user have access at leas contributor. Access level 1 belongs to contributor..

Update: 15-09-2011

While working on a project I got a tips from stackoverflow wordpress site about showing only specific author’s posts in author mode.

function cb_posts_for_current_author($query) {
     global $pagenow;

     if( 'edit.php' != $pagenow || !$query->is_admin )
     return $query;

     if( !current_user_can( 'manage_options' ) ) {
     global $user_ID;
     $query->set('author', $user_ID );
     }
     return $query;
}
add_filter('pre_get_posts', 'cb_posts_for_current_author');

thank you

6 Responses to “Adding My posts sub menu for posts section in wordpress”

  1. Do you know if it is possible to set something so that authors, or contributors, can only ever see their own posts, and NOT all the rest of them ?

    ie: Instead of seeing: Mine (1) | All (1,873) | Published (1,873) | Trash (2)

    They would only see: Mine (1)

    Thanks

    1. I think I know what needs to be done for this, but need someone to tell me how.

      In the wp-admin/edit.php file, it has various lines in the section starting with: that brings in the : Mine : All : Published : Trash : options.

      What I think it needs, for me, is to add a bit that effectively says: If User is not Admin class, then do NOT show " All : Published : Trash ".

      Am I thinking along the right lines ?

      And can this be done by a plugin, so that program updates do not remove it ?

    2. <blockquote cite="comment-11485">

      ABCDiamond: Do you know if it is possible to set something so that authors, or contributors, can only ever see their own posts, and NOT all the rest of them ?

      ie: Instead of seeing: Mine (1) | All (1,873) | Published (1,873) | Trash (2)

      They would only see: Mine (1)

      Thanks

      For the post listing in admin panel need to add a filter for "where" in query using plugin depending on user access. I think just need to little r&d about it, and I think it's possible.

  2. Hey brother you have so many posts about plugin and internal section for wordpress but there is no post about wordpress theme tutorial. Please write some posts about wordpress theme.

Leave a Reply

Your email address will not be published. Required fields are marked *