0

I'm experiencing a very odd bug while using the_excerpt() function and I have no where else too look so thought I'd see if anyone had any ideas.

I'm using the_excerpt(), on a post, like this;

enter image description here

And in the backend, the post currently has nothing set, like this;

enter image description here

I have even made sure there's nothing there by looking in the database, like this;

enter image description here

But, for some wierd reason, the_excerpt is spitting out 'pdf-sample', like this;

enter image description here

It's only happening on this post, i've removed the excerpt from other posts just to make sure they don't display this, and they don't.

If I add an excerpt into the post, it replaces and shows the correct excerpt. Then when I remove it again the excerpt is removed and pdf-sample comes back.

If I print_r get_the_excerpt;

enter image description here

It shows;

enter image description here

I'm at a bit of a loss here and can't think of anything else to try, pdf-sample is one of the media files title, which i assume is where it's coming from I just don't know why.

If you have any debug methods you could share to help me solve this it'd be greatly appreciated!

Thanks, Harry.

1 Answer 1

0

You are possibly in a secondary loop within a page, in which case you would do well to pass the ID of the post excerpt that you're trying to get.

if ( get_the_excerpt($real_id_of_post_you_want_the_excerpt_for) ) {
    the_excerpt( $real_id_of_post_you_want_the_excerpt_for );
}
3
  • Good idea. I tried adding; <?php echo get_the_excerpt(353); ?> (353 being the ID of the post that's behaving weirdly), expecting them all to now show the pdf-sample but instead something wierder happened. Even though they all have been set to show the excerpt from one post with the given ID. They are all bank other than the one that was being odd before... I'm completely confused now! I even added some random words by the <?php echo get_the_excerpt(353); ?> just to make sure I wasn't in the wrong template and they came through meaning I'm in the right place... the mystery continues. Commented Sep 15, 2016 at 13:47
  • Hmm, strange indeed! If you're using a custom query for your loop, you could try adding a wp_reset_query() at the end of the loop?
    – FaCE
    Commented Sep 15, 2016 at 15:05
  • This is on an archive page using the regular loop, I have tried adding both wp_reset_query() and wp_reset_postdata() and still this is appearing! I'm at a bit of a loss now as nothings making any sense... I feel like I'm either being really stupid or this is a bug. Thanks for your suggestions! Commented Sep 15, 2016 at 15:15

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.