#37519 closed defect (bug) (duplicate)
Excerpts not retrieved outside loop when raw excerpt is empty
Reported by: | 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)
Change History (7)
#4
@
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.
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.