How to Display Posts only from Current User
10th May 2011 | Posted by reza | 5 CommentsWhen a contributor in a multi-user site see the post list in the admin page, he could see not only his posts, but also posts from other contributors. Even he couldn’t edit the other posts, this still could be a problem if there’s alot post already and he have to search from page to page to find his posts. How about displaying his post only? This snippet will show how to do it.
Simply put the code into your theme functions.php.
function mypo_parse_query_useronly( $wp_query ) { if ( strpos( $_SERVER[ 'REQUEST_URI' ], '/wp_admin/edit.html' ) !== false ) { if ( !current_user_can( 'level_10' ) ) { global $current_user; $wp_query->set( 'author', $current_user->id ); } } } add_filter('parse_query', 'mypo_parse_query_useronly' );
Hope the snippet helps.
Credit :
Code is taken from Allen Hollman Manage Your Post Only plugin
2 Comments to “How to Display Posts only from Current User”
Add Comments (+)-
HI,
Thanks for your code , I want to know , why not use ‘add_action’ and use ‘add_filter’,
thanks.sonic
Trackbacks/Pingbacks
- Best WordPress Tutorials of May 2011
- 15 Best Collection WordPress Tricks And Hacks | Daily Syntax
- 20 Usefull WordPress Post Tutorial | WordpressRadar.com - The Best Collection of Wordpress Tutorials on the Web
Hi, thanks for the tips. BTW, is there anyway to show comment only for post by current logged in authors in wordpress admin panel?