Skip to content

Instantly share code, notes, and snippets.

@sloped
Created March 19, 2012 16:14
Show Gist options
  • Save sloped/2117659 to your computer and use it in GitHub Desktop.
Save sloped/2117659 to your computer and use it in GitHub Desktop.
Only Authored Posts Function Wordpress
<?php
/* Function to only display posts that are authored by the current user. Use capabilities to limit who is affected by this. Will not change post count list on page which can be confusing. Call using pre_get_posts() action hook
*/
function posts_by_current_author($query) {
global $pagenow;
if( 'edit.php' != $pagenow || !$query->is_admin )
return $query;
if( !current_user_can( 'capability' ) ) {
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