Make WordPress Core

Opened 5 years ago

Closed 5 years ago

#46983 closed defect (bug) (duplicate)

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

Reported by: jaredatch's profile 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:

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.


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

Change History (3)

#1 @jaredatch
5 years ago

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

Version 0, edited 5 years ago by jaredatch (next)

#2 @birgire
5 years ago

  • Keywords reporter-feedback added

Thanks for the ticket @jaredatch

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

#3 @SergeyBiryukov
5 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.