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 want display authors'posts with the code below but authors' name aren't showing. What is wrong?

<? // query test
$qry = $wpdb->get_results( $wpdb->prepare("
FROM $wpdb->posts
WHERE post_type ='post'
AND post_status='publish'
order by 'ID' DESC

echo "<table width=100% cellspacing=1 cellpadding=5 bgColor='#cccccc'>";

foreach ( $qry AS $k => $v ){

$qry_name = $wpdb->get_results( $wpdb->prepare("
SELECT user_nicename AS USER_NAME
FROM 'wp-users' AS a
LEFT JOIN 'wp-posts' AS b
ON a.ID = b.post_author
WHERE b.post_author = a.ID

$ID = $v->ID;
$title = stripslashes(mb_substr($v->post_title, 0,20,"utf-8"));
$ddate = $v->post_modified;
$name = $v->user_nicename;
$link = '<a href=/archives/'.$ID.'>';
$list = "<tr><td bgColor='#ffffff'>".$ID."</td><td bgColor='#ffffff'>".$link.$target.$title."</a></td><td bgColor='#ffffff'> on ".$ddate."</td><td bgColor='#ffffff'>".$qry_name[0]->USER_NAME."</td></tr>";
echo $list;

echo "</table>";
share|improve this question

Your table names are wrong. note in your first query the use of $wpdb->posts to reference the posts table.

however- this is a very simple query that can be done via the API rather than writing SQL queries from scratch. Use a new WP_Query instance instead.

share|improve this answer
Thanks a lot. resolved. – JayteeHong Aug 16 '12 at 2:35

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.