I have a php function that should print last three posts with title and excerpt.

For the first post printed there is no excerpt.

Here is the code:

  $posts = wp_get_recent_posts( array('numberposts' => 3, 'post_status' => 'publish')  );
  foreach ($posts as $post)
    echo "<h2 style='font-size:18px'>".$post['post_title']."</h2>";
         echo $post['post_excerpt']." <a href='".get_permalink($post['ID'])."'     style='font-size: 17px;'><b>Continue...</b></a>";
    else echo 'no excerpt';
    echo "<br><br />";

I want to show the excerpt for the first post printed too (the last posted one). What is wrong in my code? Why it's not working for the first post printed?

  • Does "no excerpt" get output?
    – anu
    Oct 11, 2012 at 21:47
  • make sure that the first/latest post has a custom-written excerpt.
    – Michael
    Oct 11, 2012 at 22:19

1 Answer 1


Excerpt is stored in database and available in post object only if it was added manually in post editor. Do not access such properties directly, use template tags instead - get_the_excerpt() in this case.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.