Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

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)
  {
    setup_postdata($post);
    echo "<h2 style='font-size:18px'>".$post['post_title']."</h2>";
    if($post['post_excerpt']) 
         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?

share|improve this question
    
Does "no excerpt" get output? –  anu Oct 11 '12 at 21:47
    
make sure that the first/latest post has a custom-written excerpt. –  Michael Oct 11 '12 at 22:19

1 Answer 1

up vote 1 down vote accepted

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.

share|improve this answer

Your Answer

 
discard

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.