0

I have set users to only see their own posts. But the total number of articles is still visible. Can we limit it to its own number of articles? How can it be done without plugins? related picture here:

https://imgur.com/a/iOeQBEn

I restricted the users to their own posts with the code below. But as the picture above shows, although the publication is one, the number of publications seems to be four. How can I make the number of publications?

function posts_for_current_author($query) {
    global $pagenow;
 
    if( 'edit.php' != $pagenow || !$query->is_admin )
        return $query;
 
    if( !current_user_can( 'edit_others_posts' ) ) {
        global $user_ID;
        $query->set('author', $user_ID );
    }
    return $query;
}
add_filter('pre_get_posts', 'posts_for_current_author');
  • How have you set the users to only see their own posts? You might be able to extend that to the 'all posts' number too. – Rup Jul 4 at 15:42
  • What is the user_role here? – Sabbir Hasan Jul 4 at 18:46
  • function posts_for_current_author($query) { global $pagenow; if( 'edit.php' != $pagenow || !$query->is_admin ) return $query; if( !current_user_can( 'edit_others_posts' ) ) { global $user_ID; $query->set('author', $user_ID ); } return $query; } add_filter('pre_get_posts', 'posts_for_current_author'); – Mehmet Şar Jul 5 at 11:16
  • user role: author – Mehmet Şar Jul 5 at 11:17
  • Thanks. Please edit that into the question where it will be easier to read than in a comment. – Rup Jul 5 at 11:29

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.