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.


3 Answers 3


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]

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";

  [1]: https://stackoverflow.com/users/741747/sheikh-heera
  • Meh. Somehow I missed that you already had a solution :/
    – kaiser
    Mar 20, 2013 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(); ?>

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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