WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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;
$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.

share|improve this question

migrated from stackoverflow.com Mar 20 '13 at 12:16

This question came from our site for professional and enthusiast programmers.

o great thanks. it is the script which i need. – Muhammad Sajid Mar 20 '13 at 12:00
You are welcome :-) – The Alpha Mar 20 '13 at 12:01

Thanks to Sheikh Heera

if ( is_user_logged_in() ):

    global $current_user;
    $author_query = array('posts_per_page' => '-1','author' => $current_user->ID);
    $author_posts = new WP_Query($author_query);
    while($author_posts->have_posts()) : $author_posts->the_post();
        <a href="<?php the_permalink(); ?>" title="<?php the_title_attribute(); ?>"><?php the_title(); ?></a>       

else :

    echo "not logged in";

share|improve this answer
Meh. Somehow I missed that you already had a solution :/ – kaiser Mar 20 '13 at 12:49

The following mini-plugin adds a dashboard widget that queries posts from the current user that have publish as post status. You can see get_current_user_id() in use.

defined( 'ABSPATH' ) OR exit;
 * Plugin Name: (#91605) Dashboard Widget - User posts

add_action( 'wp_dashboard_setup', 'wpse91605_dbwidget_user_posts' );
function wpse91605_dbwidget_user_posts()
        ,_e( 'Your published posts', 'your_textdomain' )
function wpse91605_dbwidget_user_posts_cb()
    $query = new WP_Query( array(
         'author'         => get_current_user_id()
        ,'post_status'    => 'publish'
        ,'posts_per_page' => -1
        ,'showposts'      => -1
        ,'nopaging'       => true
    ) );
    if ( $query->have_posts() )
        while( $query->have_posts )
            <li><a href="<?php the_permalink(); ?>" title="<?php the_title_attribute(); ?>">
                <?php the_title(); ?>
share|improve this answer

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'.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.