Make WordPress Core

Opened 8 years ago

Closed 8 years ago

Last modified 8 years ago

#37519 closed defect (bug) (duplicate)

Excerpts not retrieved outside loop when raw excerpt is empty

Reported by: iandunn's profile iandunn Owned by:
Milestone: Priority: normal
Severity: normal Version: 4.5
Component: Posts, Post Types Keywords: has-unit-tests has-patch
Focuses: template Cc:

Description

#27246 / r36319 introduced the ability to fetch the excerpt for a post when outside the Loop, but it only works if the post has an excerpt manually assigned.

If the raw post_excerpt is empty, then a notice is thrown and an empty string is returned.

Notice: Trying to get property of non-object in src/wp-includes/post-template.php on line 298

I expected it to automatically generate the an excerpt from the post_content, like it would inside the Loop.

The unit test from r36320 only tests the case where an excerpt is manually assigned.

This snippet in an mu-plugin will reproduce it:

add_action( 'init', function() {
	var_dump( get_the_excerpt( get_post( 1 ) ) );
	wp_die();
} );

Attachments (2)

37519-tests.diff (810 bytes) - added by iandunn 8 years ago.
37519.diff (3.0 KB) - added by iandunn 8 years ago.

Download all attachments as: .zip

Change History (7)

@iandunn
8 years ago

@iandunn
8 years ago

#1 @iandunn
8 years ago

37519.diff fixes the bug for me, but the new unit test still fails. I'm guessing the post factory isn't setup to automatically generate excerpts the way the actual code does, but don't have time to dig into that right now.

#2 @iandunn
8 years ago

  • Keywords has-unit-tests has-patch added

#4 @swissspidy
8 years ago

  • Milestone Awaiting Review deleted
  • Resolution set to duplicate
  • Status changed from new to closed

Thanks for the patch, @iandunn!

Since we already made some progress on that problem in #36934, would you mind sharing this there? There's a whole lot to cover with such a change so I suggest reading through the previous comments & patches.

#5 @iandunn
8 years ago

Doh, my bad, I didn't find that when I searched for tickets mentioning #27246 or r36319.

I tested 36934a.diff and 36934b.diff, and they both solve the specific issue raised here. It doesn't look like my patch would add anything to what's already been done there.

Note: See TracTickets for help on using tickets.