WordPress.org

Make WordPress Core

Opened 3 years ago

Closed 3 years ago

Last modified 4 months ago

#17034 closed defect (bug) (wontfix)

E_NOTICE with WP_DEBUG when calling get_the_ID()

Reported by: tillkruess Owned by:
Milestone: Priority: normal
Severity: minor Version: 3.1
Component: General Keywords:
Focuses: Cc:

Description

When get_the_ID() is called, but $post is NULL (for example on a 404 page) a E_NOTICE is caused when WP_DEBUG is set to TRUE.

Change History (4)

comment:1 tillkruess3 years ago

  • Cc me@… added

comment:2 scribu3 years ago

  • Milestone Awaiting Review deleted
  • Resolution set to wontfix
  • Status changed from new to closed

get_the_ID() should only be called inside The Loop.

Version 0, edited 3 years ago by scribu (next)

comment:3 follow-up: jtsternberg4 months ago

Curious, why should get_the_ID() only be called from inside The Loop? Seems if we addressed the notice issue, it would be a decent way to check if there is a post object available.

comment:4 in reply to: ↑ 3 SergeyBiryukov4 months ago

Replying to jtsternberg:

Seems if we addressed the notice issue, it would be a decent way to check if there is a post object available.

get_post() appears to be the correct way to check for that.

Note: See TracTickets for help on using tickets.