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'm trying to get text only content of posts by ID. I modified this function as follows, but at the moment it returns nothing. I cannot see what's wrong with it.

function get_the_excerpt_id($post_id) {
    $find = get_posts($post_id); 
    $excerpt = $find->post_content;

    $excerpt = strip_tags($excerpt);
    $output = substr($excerpt, 0, 100);

  return $output;
}

Any ideas what's missing?

Marvellous

share|improve this question

1 Answer 1

up vote 0 down vote accepted

Instead of using get_posts, which you would use if you wanted to retrieve multiple posts in a loop, you should use get_post, which only retrieves one post by an ID. There is also a built-in excerpt so you might want to go with retrieving post_excerpt.

function get_the_excerpt_id($post_id) {
    $find = get_post($post_id); 
    $excerpt = $find->post_excerpt;

    $excerpt = strip_tags($excerpt);
    $output = substr($excerpt, 0, 100);

return $output;
}
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.