Opened 6 years ago
Closed 6 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: |
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)
Note: See
TracTickets for help on using
tickets.
Original post should read if the Blog page does not have anything inside the excerpt AND the post content is empty :)