0

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

0

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;
}

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.