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

In the code below represents a link list of recent posts. I'm just trying to write out the post name, along with the post excerpt if one exists. So I'm using the get_link_excerpt($post) function in order to determine if the current post in the for loop has an excerpt.

It works fine if the post has an excerpt, however, if it doesn't, the get_the_excerpt() function is returning its own excerpt crafted from the current page's content.

In this case, I'm placing this function on the home page, so every post that does not explicitly have a snippet is getting a virtual excerpt from the home page's content.

Apparently, I'm passing $post improperly, what's the correct way to do it here?

function show_footer_recent(){
    $myquery = new WP_Query();$myquery->query(array('post__not_in' => get_option('sticky_posts')));
    $myrecentpostscount = $myquery->found_posts;
    if ($myrecentpostscount > 0){ ?>
        <ul><i>Latest News & Articles</i>
            <?php global $post;$myrecentposts = get_posts(array('post__not_in' => get_option('sticky_posts'),'numberposts' => get_option('cb2_recent_count')));
            foreach($myrecentposts as  $idxrecent=>$post) { ?>
                <li class="page_item">
                    <a href="<?php the_permalink(); ?>"><?php the_title(); ?></a><?php echo get_link_excerpt(); ?>
                </li><?php } ?>
<?php }} 

function get_link_excerpt(){
    $LinkExcerpt = strip_tags(substr(get_the_excerpt(), 0, 75 ));
    if($LinkExcerpt != '')
        return ": ".$LinkExcerpt."...";
    return false;
share|improve this question
get_the_excerpt doesn't accept any arguments. it will return the excerpt of the current post in the loop (of the global $post) – onetrickpony Jan 13 '11 at 22:47
up vote 2 down vote accepted

I got it working. Here's what I had to do in my utility function...

function get_link_excerpt(){
$LinkExcerpt = strip_tags(substr(get_the_excerpt(), 0, 75 ));
return ": ".$LinkExcerpt."...";
return false;
share|improve this answer
you could remove the $post argument, it's redundant – onetrickpony Jan 13 '11 at 23:02
Thanks AA, I missed that one. :) – Scott B Jan 13 '11 at 23:17

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.