roles - block read other post except own post

by Jennifer   Last Updated May 16, 2019 05:08 AM

im searching how i can do to disable see and read any post, except his own to a custom role

i began with this code but itsnt works because its restrict the others. can u help me? i tried with plugin of control but it blocked to read and edit his own role and i cant set the post like private because i have a function that begin when the post published.

function posts_for_current_author($query) {
    global $pagenow;
    $tempuser = wp_get_current_user();
    if( 'edit.php' != $pagenow || !$query->is_admin )
        return $query;

    if( in_array( 'client-event', (array) $tempuser->roles ) ) {
        add_action( 'views_edit-post', 'child_remove_some_post_views' );
        global $user_ID;
        $query->set('author', $user_ID );
    return $query;
function child_remove_some_post_views( $views ) {
    return $views;
add_filter('pre_get_posts', 'posts_for_current_author');

Related Questions

Updated November 08, 2018 09:08 AM

Updated July 15, 2019 15:08 PM

Updated June 21, 2017 17:08 PM

Updated May 22, 2016 08:03 AM