I have a script in archive.php, which is outside the loop, that calls on the function get_blog_links() to list all posts that belong the the current category (my "blog" category).

I'm trying to do some trace testing inside the "get_blog_excerpt() function in order to write out either the post excerpt or (if no excerpt appears) the first 55 words of content (the_excerpt) for each post.

However, I'm unable to obtain a reference to the_excerpt in my function.

Any help much appreciated.

//Blog Listing
function get_blog_links(){
    $myposts = get_posts();
    echo '<div>'; 
    echo '<ul>'; foreach($myposts as $idx=>$post){ ?>
            <li><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a>
            <?php echo get_blog_excerpt();?></li>
    <?php } 
    echo '</ul></div>';

function get_blog_excerpt(){
    // return get_the_excerpt(); WORKS
    // return the_permalink();  WORKS
    // return the_excerpt(); DOES NOT WORK?
    // return get_the_content(); DOES NOT WORK?

1 Answer 1


I think you have to setup_postdata() with get_posts() to get things that rely on global variables to work. or explicitly pass the post id with the function.

  • That's it Milo. setup_postdata() has got me on a couple of occasions. Memory is soft :-) Thanks!
    – Scott B
    Commented Jun 17, 2011 at 18:58

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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