Created
November 9, 2021 22:09
-
-
Save websitecareio/4448220caaef3b3bb265794594aa95b1 to your computer and use it in GitHub Desktop.
Limit WordPress posts by author.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
add_filter('pre_get_posts', 'posts_for_current_author'); | |
function posts_for_current_author($query) { | |
if(!is_admin()) { return $query; } | |
global $pagenow; | |
if( 'upload.php' == $pagenow || !$query->is_admin ) { | |
if( !current_user_can( 'edit_others_posts' ) ) { | |
global $user_ID; | |
$query->set('author', $user_ID ); | |
} | |
} | |
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; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment