Make WordPress Core

Opened 7 years ago

Closed 7 years ago

#46983 closed defect (bug) (duplicate)

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

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

Description

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
7 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 7 years ago by jaredatch (previous) (diff)

#2 @birgire
7 years ago

  • Keywords reporter-feedback added

Thanks for the ticket @jaredatch

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

#3 @SergeyBiryukov
7 years ago

  • Component GeneralPosts, Post Types
  • Milestone Awaiting Review
  • Resolutionduplicate
  • Status newclosed

Appears to be the same issue as in #42814.

Note: See TracTickets for help on using tickets.