How To Allow Only Post Creator Can See His Own Post

// Current User Can Show His Own Post

add_action('pre_get_posts', 'filter_posts_list');
function filter_posts_list($query)
{
    //$pagenow holds the name of the current page being viewed
     global $pagenow;

    //$current_user uses the get_currentuserinfo() method to get the currently logged in user's data
     global $current_user;
     get_currentuserinfo();
   
        //Shouldn't happen for the admin, but for any role with the edit_posts capability and only on the posts list page, that is edit.php
        if(!current_user_can('administrator') && current_user_can('edit_posts') && ('edit.php' == $pagenow))
     {
        //global $query's set() method for setting the author as the current user's id
        $query->set('author', $current_user->ID);
$screen = get_current_screen();
add_filter('views_'.$screen->id, 'remove_post_counts');
        }
}



function remove_post_counts($posts_count_disp)
{
    //$posts_count_disp contains the 3 links, we keep 'Mine' and remove the other two.
    unset($posts_count_disp['all']);
        unset($posts_count_disp['publish']);
   
        return $posts_count_disp;
}


//Current User Can Show His Own Post

Comments

Popular posts from this blog

Remove Add New Post Sub Menu From Custom Post

How To Remove and Add Visit Site Menu From WordPress Admin Bar?

Register Custom Post Type