WordPress.org

Forums

Only show suthors their custom post types in dashboard. (10 posts)

  1. eljacko876
    Member
    Posted 2 years ago #

    I have created a custom post type and would like to limit the authors of that custom post type to only see the posts they have created, as opposed to showing them custom posts created by other users as well as their own.
    I have tried customizing the solution found here for custom posts, by editing 'edit.php' to 'edit.php?post_type=MY CUSTOM POST TYPE', an putting in in my function.php , but that did not work. I'm sure someone has figured this out.
    Thank you in advance.

  2. deepbevel
    Member
    Posted 2 years ago #

    I use this css mod in functions.php to mod the admin posts filter to only show the current user's posts.

    function posts_filter() {
        echo '<style type="text/css"> 
    
    /*admin all-posts screen*/
    
    /*#posts-filter,*/
    
    /*ul.subsubsub .mine,*/
    ul.subsubsub .all,
    ul.subsubsub .publish,
    ul.subsubsub .sticky,
    ul.subsubsub .trash,
    ul.subsubsub .draft,
    ul.subsubsub .pending,
    .view-switch,
    .tablenav ,
    .row-actions .editinline,
    .check-column
    * {display:none;}
        </style>';
    }
    add_action('admin_head', 'posts_filter');

    not sure if it works with custom taxonmies and post types..

  3. eljacko876
    Member
    Posted 2 years ago #

    Thank you, but that did not seem to work, not sure it is for posts, but its not working for custom post types. Thank you so much for responding anyway, any other ideas?

  4. deepbevel
    Member
    Posted 2 years ago #

    if you use a web page inspector tool like firebug you could probably find the correct css then just add the selectors between
    
    function posts_filter() {
        echo '<style type="text/css"> 
    
    your css code here
    
    * {display:none;}
        </style>';
    }
    add_action('admin_head', 'posts_filter');

    anyway here's screen shot of what I posted working on my site

  5. deepbevel
    Member
    Posted 2 years ago #

    You could also go at it another way, use the Adminimize plugin to remove access to the posts link in the admin menu. Then just allow users access posts for editing via the front-end post edit link.

  6. deepbevel
    Member
    Posted 2 years ago #

    but, the one problem with that is when users delete posts they will be redirected to the admin posts filter page...

    but you could possibly fix that this way:

    add_action('trashed_post','my_trashed_post_handler',10,1);
    function my_trashed_post_handler($post_id)
    {
        wp_redirect( get_option('siteurl') );
        exit;
    }
  7. eljacko876
    Member
    Posted 2 years ago #

    I really appreciate your help, I do have firebug, and it was motivation to see the screenshot, thanks for the effort, I owe you either way!...
    here is my screen shot this is front he admin view, but i just realized , its not even showing the author in that list. Still no luck on this, have you ever used custom posts?

  8. deepbevel
    Member
    Posted 2 years ago #

    yes, I've used custom posts and taxonomies. But I don't recall that It made any difference in the admin post list.

  9. deepbevel
    Member
    Posted 2 years ago #

    or better said, I would expect that the same css selectors would work for custom post types.

    How did you acheive your setup in the screenshot? it appears as though you have what you were going for,
    and are those both the same author's posts? is that not the goal? sorry if I'm missing something..

  10. deepbevel
    Member
    Posted 2 years ago #

    my method is really not so fancy, all it does is remove the admin post list sorting capability for the author role, leaving "mine" as the only sorting option. But it worked for me.

    I was using this solution before (see example 4, it's for posts and media), but I had strange issues with it when used with other roles and capabilities plugins.

    still, you might try it with your custom post type defined in this part of the code

    foreach( $types as $type ) {
            $query = array(
                'author'      => $current_user->ID,
                'post_type'   => 'post',
                'post_status' => $type['status']

Topic Closed

This topic has been closed to new replies.

About this Topic