How to List Posts by Authors at WordPress Blog

by Hiroshi on November 17, 2008

in Hacks, WordPress

Ever insisted by another blog partner to list his posts separately? Many blogs are run by more than one authors. To achieve this you first need to know the ID of each author or specific author you want to list posts.

On your WordPress admin area, go to Users. While you place your mouse over an any username, look for the URL address appearing in your browser’s status bar. The user ID is displayed in the URL. Find any WordPress user ID. Suppose it is 7. You want to list all posts published by author having ID 7.

Once you have the ID(s), paste the following code where you want to list the posts from a specific author:

$numposts = $wpdb->get_results("SELECT * FROM $wpdb->posts WHERE post_author = 7");
 
echo "Posts by Author 7";
<ul>
foreach ($numposts as $numpost) {
	echo "<li>".$numpost->post_title."</li>";
}
</ul>

To list posts from a second author, repeat the above code and change the post_author which is ID of that specific author in the query.

Related Posts

Previous post:

Next post: