0

The problem I'm having is that the_excerpt() isn't returning the content from the post's "Excerpt" field. Instead, it's returning the first 55 words of the post, as though the "Excerpt" field is empty.

My code is very simple - inside the loop, I have:

if( has_excerpt() ) {
    the_excerpt();
} else {
    the_content();
}

Is there something that needs to be done to tell wordpress to use the "Excerpt" field.

0

Have you tried using the example from the codex?

if ( ! has_excerpt() ) {
      the_content();
} else { 
      the_excerpt();
}
| improve this answer | |
0

@shanebp - yes I did that, but that shows the 55 word excerpt.

I resolved this as follows ..

I discovered that the excerpt is stored in the WP_Post class field post_excerpt, so I got it directly with ...

$the_post = get_post();
$post_excerpt = apply_filters('the_excerpt', $the_post->post_excerpt);
echo $post_excerpt;

I would be happy to hear from anyone if there is a better way, and also why the_excerpt() doesn't give that field content.

Thanks

| improve this answer | |
  • Looking now, the_excerpt should do exactly that, echo $post->post_excerpt filtered through the_excerpt, unless this is a password protected post or unless there is a get_the_excerpt filter that changes the return value. – Rup Sep 30 '19 at 9:33

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.