Title: Get posts from a specific user.
Last modified: August 19, 2016

---

# Get posts from a specific user.

 *  Resolved [cip6791](https://wordpress.org/support/users/cip6791/)
 * (@cip6791)
 * [15 years, 7 months ago](https://wordpress.org/support/topic/get-posts-from-a-specific-user/)
 * Hello,
 * I am trying to get the posts from a logged in user.
 * This code displays the user that is logged in and the user id.
 *     ```
       if ( is_user_logged_in() ) {
   
       global $current_user;
             get_currentuserinfo();
   
           echo 'Welcome, registered user!';
       echo 'User ID: ' . $current_user->ID . "\n";
       } else {
           echo 'Welcome, visitor!';
       };
       ```
   
 * Welcome, registered user!User ID: 1
 * How can I get all the posts that the user with the ID:1 has posted?
    Thank you

Viewing 5 replies - 1 through 5 (of 5 total)

 *  [esmi](https://wordpress.org/support/users/esmi/)
 * (@esmi)
 * [15 years, 7 months ago](https://wordpress.org/support/topic/get-posts-from-a-specific-user/#post-1692182)
 * [http://codex.wordpress.org/Function_Reference/query_posts#Author_Parameters](http://codex.wordpress.org/Function_Reference/query_posts#Author_Parameters)
 *  Thread Starter [cip6791](https://wordpress.org/support/users/cip6791/)
 * (@cip6791)
 * [15 years, 7 months ago](https://wordpress.org/support/topic/get-posts-from-a-specific-user/#post-1692262)
 *     ```
       <?php
       if ( is_user_logged_in() ) {
   
       global $current_user;
             get_currentuserinfo();
   
       echo 'User ID: ' . $current_user->ID . "\n";
   
       //The Query
       query_posts('author=2');
   
       //The Loop
       if ( have_posts() ) : while ( have_posts() ) : the_post();
       the_title();
       echo "<br>";
       endwhile; else:
       echo "The user has not contributed anything!";
       endif;
   
       //Reset Query
       wp_reset_query();
   
       } else {
           echo 'Welcome, visitor!';
       };
       ?>
       ```
   
 * Ok .. this is what I have so far. I have one problem here: query_posts(‘author
   =2’); How do I replace the 2 with the current user ID?
 *  [Chinmoy](https://wordpress.org/support/users/chinmoy/)
 * (@chinmoy)
 * [15 years, 7 months ago](https://wordpress.org/support/topic/get-posts-from-a-specific-user/#post-1692264)
 * `query_posts('author='.$current_user->ID );`
 *  Thread Starter [cip6791](https://wordpress.org/support/users/cip6791/)
 * (@cip6791)
 * [15 years, 7 months ago](https://wordpress.org/support/topic/get-posts-from-a-specific-user/#post-1692265)
 * Nevermind … I figured it out. Had to define it in $args. 🙂
 * thanks Esmi & chinmoy29
 *  Thread Starter [cip6791](https://wordpress.org/support/users/cip6791/)
 * (@cip6791)
 * [15 years, 7 months ago](https://wordpress.org/support/topic/get-posts-from-a-specific-user/#post-1692267)
 * Now if I would want to create an edit and delete link …

Viewing 5 replies - 1 through 5 (of 5 total)

The topic ‘Get posts from a specific user.’ is closed to new replies.

## Tags

 * [get](https://wordpress.org/support/topic-tag/get/)
 * [posts](https://wordpress.org/support/topic-tag/posts/)
 * [user](https://wordpress.org/support/topic-tag/user/)

 * In: [Fixing WordPress](https://wordpress.org/support/forum/how-to-and-troubleshooting/)
 * 5 replies
 * 3 participants
 * Last reply from: [cip6791](https://wordpress.org/support/users/cip6791/)
 * Last activity: [15 years, 7 months ago](https://wordpress.org/support/topic/get-posts-from-a-specific-user/#post-1692267)
 * Status: resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
