Get excerpt using get_the_excerpt outside a loop

I have a code that call get_the_title() and it works, but get_the_excerpt() return empty. How can i make it work?

This code is inside a plugin called “WP Facebook Open Graph protocol”. Here’s the part i want to change:

if (is_singular('post')) {
  if (has_excerpt($post->ID)) {
    echo "\t<meta property='og:description' content="".esc_attr(strip_tags(get_the_excerpt($post->ID)))."" />\n";
    echo "\t<meta property='og:description' content="". [?] ."" />\n";
  echo "\t<meta property='og:description' content="".get_bloginfo("description')."' />\n";

Here, has_excerpt always fail, and get_the_excerpt($post->ID) don’t work anymore (deprecated).

So, how can i display the excerpt there?

ps: I’m using “Advanced Excerpt” plugin as well


I found this question when looking how to do this without the post object.

My additional research turned up this slick technique:

$text = apply_filters('the_excerpt', get_post_field('post_excerpt', $post_id));

Leave a Comment