HomeArticles

Show only user's posts in post overview

Stefan Baumgartner

Written by @ddprrt

More on Wordpress

This one restricts authors to only view their own posts in Wordpress’ post overview:

function mypo_parse_query_useronly( $wp_query ) {
if ( strpos( $_SERVER[ 'REQUEST_URI' ], '/wp-admin/edit.php' ) !== false || strpos( $_SERVER[ 'REQUEST_URI' ], '/wp-admin/upload.php' ) !== false ) {
if ( !current_user_can( 'update_core' ) ) {
global $current_user;
$wp_query->set( 'author', $current_user->id );
}
}
}

add_filter('parse_query', 'mypo_parse_query_useronly' );

Add this part to your functions.php or include it in a seperate plugin

More articles on Wordpress

Stay up to date!

3-4 updates per month, no tracking, spam-free, hand-crafted. Our newsletter gives you links, updates on fettblog.eu, conference talks, coding soundtracks, and much more.