Make WordPress Core

Opened 2 years ago

Closed 2 years ago

#46983 closed defect (bug) (duplicate)

get_the_excerpt() PHP warning if no except/post_content exists.

Reported by: jaredatch Owned by:
Milestone: Priority: normal
Severity: normal Version: 5.1.1
Component: Posts, Post Types Keywords: reporter-feedback
Focuses: Cc:


In blog post single templates, it's not uncommon to have a blog "header" that pulls from whatever is set in the page_for_posts option. Example: https://cl.ly/2d27f2540fdc

This can be accomplished in the single post template by checking.

$title = get_the_title( get_option( 'page_for_posts' ) );
$desc  = get_the_excerpt( get_option( 'page_for_posts' ) );

However if the Blog page does not have anything inside the excerpt OR the post content, it triggers a PHP error.

See https://cl.ly/7dc933f2ef76

If there is no post content or excerpt, the function should return an empty string.

Change History (3)

#1 @jaredatch
2 years ago

Original post should read if the Blog page does not have anything inside the excerpt AND the post content is empty :)

Last edited 2 years ago by jaredatch (previous) (diff)

#2 @birgire
2 years ago

  • Keywords reporter-feedback added

Thanks for the ticket @jaredatch

I suspect this might be covered in #42814 for 5.2 ?

#3 @SergeyBiryukov
2 years ago

  • Component changed from General to Posts, Post Types
  • Milestone Awaiting Review deleted
  • Resolution set to duplicate
  • Status changed from new to closed

Appears to be the same issue as in #42814.

Note: See TracTickets for help on using tickets.