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 have the following function which I use to show the author name,author avatar and the author biography in a div. I need to show the title of the latest post by the author along with this. Can anyone help?

function ajaxified_function() 
    $response = new WP_Ajax_Response();
    $id        = $_POST['author_id'];
    $auth_name = get_the_author_meta('display_name', $id);
    $avatar    = get_avatar($id);
    $desc      = get_the_author_meta('description',$id);
    $auth_desig  = get_the_author_meta('designation', $id);
    $output = "<div id='bloggers_title'>$auth_name</div>\n
           <div id='bloggers_desig'>$auth_desig</div>\n
           <div id='bloggers_avatar'>$avatar</div>\n
           <div id='bloggers_desc'>$desc</div>\n";
    'what' => 'has',
    'data' => $output
share|improve this question
up vote 3 down vote accepted

You can get the latest post of an author adding the following code to your function:

$latest_post = get_posts( array(
        'author'      => $id,
        'orderby'     => 'date',
        'numberposts' => 1

// Since get_posts() returns an array, but we know we only
// need one element, let's just get the element we need.
$latest_post = $latest_post[0];

Then modify your $output, adding the data you need (specifically guid for the permalink, and post_title for the title), for example:

$output .= "<div id='bloggers_latest_post'>
                <a href='$latest_post->guid'>$latest_post->post_title</a>
share|improve this answer
Thank you very much....That was a great help you did.... – MidhuN Apr 8 '13 at 13:28
If this as solved your problem, you can accept the answer and thus closing the issue. – Sunyatasattva Apr 8 '13 at 13:34
It said 2 more minutes to accept the answer..I think now I can do that – MidhuN Apr 8 '13 at 13:50
Hi.. I have a small problem in the ajax question. Can you please help me. Till today morning it was working. But after that wen I saw suddenly it was not working. I think it is where I register the js and using the WP_localize_script. Can you please help me with that? – MidhuN Apr 9 '13 at 15:11
You know that things don't automatically stop working in code, right? Did you use version control? Can you go back and see what is the problem? Are you debugging? What errors does it give? How am I supposed to help you with such a general question? – Sunyatasattva Apr 10 '13 at 8:26

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.