One of wprecipes.com readers, Emarts, asked on the forum how he can list posts from a specific author. In this recipe, I’ll show you how we can do that, buy using the $wpdb object and the get_results() method.
One of wprecipes.com readers, Emarts, asked on the forum how he can list posts from a specific author. In this recipe, I’ll show you how we can do that, buy using the $wpdb object and the get_results() method.
To achieve this recipe, you first need to know the ID of each author you want to list posts.
On your WordPress dashboard, go to Users. When you put your mouse over an username, look for the adress appearing in your browser's status bar. The user ID is displayed in the url.

Once you have the ID(s), paste the following code where you want to list the post from a specific author:
$numposts = $wpdb->get_results("SELECT * FROM $wpdb->posts WHERE post_author = 1");
echo "Posts by Author 1";
<ul>
foreach ($numposts as $numpost) {
echo "<li>".$numpost->post_title."</li>";
}
</ul>
To list posts from a second author, simply repeat the above code and change the post_author in the query.
5 Responses
THANKS!!
Exactly what I needed (almost)
Do you know how I would edit the code to display the posts of the currently logged in user instead of a specific author?
Trackbacks: