Ask your WordPress questions! Pay money and get answers fast! Comodo Trusted Site Seal
Official PayPal Seal

Retrieve author name from $post->post_author (or other $post val) WordPress


I've created a custom database request in order to show the most popular posts on a site, now I'd like to publish the author of each of these posts. I haven't been successful in finding a method for retrieving the author name from $post->post_author however, which only gives me the ID of the author.

If it's of any help, here's my custom database call:

$result = $wpdb->get_results("SELECT ID, comment_count, post_title, post_date, post_author FROM $wpdb->posts ORDER BY comment_count DESC LIMIT 0, 5");

I've noticed some using "post_author_link" in a couple of tutorials but haven't been able to figure out if it can display the actual author name.

Answers (1)


Utkarsh Kukreti answers:

$user_info = get_userdata($post->post_author);
$first = $user_info->first_name;
$last = $user_info->last_name;

Staffan Estberg comments:

Awesome, thanks!