I am creating a back-end dashboard where I need to show all the post assigned to current user by the wp admin.
I assign user role to Author and while creating post (as a wp
admin) just assign this post to some author from Author drop-down.
So I need to show posts with status Publish. I am now using simple query post but it is returning all posts.
global $current_user;
get_currentuserinfo();
$user_id = $current_user->ID; // for current user it is 2
$query = array(
'post_type' => 'post',
'post_author' => $user_id,
'post_status' => array('publish')
);
$my_posts = query_posts($query);
I also hard-coded post_author to 2
I also tried $my_post = new WP_Query(array( 'post_author' => '2' ));
but fail.
The shortest possible answer would be to correct ‘post_author’ to ‘author’, since that is the key WP is looking for. If a key is incorrect or misspelled it will be ignored, as was the case with ‘post_author’.
Thanks to [Sheikh Heera][1]
The following mini-plugin adds a dashboard widget that queries posts from the current user that have
publish
as post status. You can seeget_current_user_id()
in use.