Make WordPress Core

Opened 13 years ago

Closed 10 years ago

Last modified 10 years ago

#17034 closed defect (bug) (fixed)

E_NOTICE with WP_DEBUG when calling get_the_ID()

Reported by: tillkruess's profile tillkruess Owned by: wonderboymusic's profile wonderboymusic
Milestone: 4.0 Priority: normal
Severity: minor Version: 3.1
Component: Posts, Post Types 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.

Attachments (2)

28572.diff (456 bytes) - added by UmeshSingla 10 years ago.
Fixes get_the_ID() if get_post() returns null
17034.diff (456 bytes) - added by UmeshSingla 10 years ago.
Fixes get_the_ID() if get_post() returns null

Download all attachments as: .zip

Change History (14)

#1 @tillkruess
13 years ago

  • Cc me@… added

#2 @scribu
13 years ago

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

get_the_ID() should only be called from inside The Loop.

Last edited 13 years ago by scribu (previous) (diff)

#3 follow-up: @jtsternberg
11 years 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.

#4 in reply to: ↑ 3 ; follow-up: @SergeyBiryukov
11 years 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.

#5 @SergeyBiryukov
10 years ago

#28572 was marked as a duplicate.

#6 @SergeyBiryukov
10 years ago

  • Component changed from General to Posts, Post Types

#7 in reply to: ↑ 4 ; follow-up: @UmeshSingla
10 years ago

Replying to SergeyBiryukov

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

get_post() can't be used as well, it returns the ID for the latest post on wp-signup.php, I didn't get the logic for that.

#8 in reply to: ↑ 7 ; follow-up: @SergeyBiryukov
10 years ago

  • Milestone set to 4.0
  • Resolution wontfix deleted
  • Status changed from closed to reopened

Replying to UmeshSingla:

get_post() can't be used as well, it returns the ID for the latest post on wp-signup.php, I didn't get the logic for that.

That sounds like a separate issue.

We could probably reconsider this to avoid the notice. Your patch on #28572 seems good.

#9 in reply to: ↑ 8 ; follow-up: @UmeshSingla
10 years ago

Replying to SergeyBiryukov:

That sounds like a separate issue.

We could probably reconsider this to avoid the notice. Your patch on #28572 seems good.

Yes, I'll try too replicate the get_post() issue, If it confirms, I'll go for a separate ticket and for this ticket do i need to submit the patch here again?

Last edited 10 years ago by UmeshSingla (previous) (diff)

#10 in reply to: ↑ 9 @SergeyBiryukov
10 years ago

Replying to UmeshSingla:

do i need to submit the patch here again?

Yes, please.

@UmeshSingla
10 years ago

Fixes get_the_ID() if get_post() returns null

@UmeshSingla
10 years ago

Fixes get_the_ID() if get_post() returns null

#11 @wonderboymusic
10 years ago

  • Owner set to wonderboymusic
  • Resolution set to fixed
  • Status changed from reopened to closed

In 28844:

Check for the existence of $post before using it in get_the_ID(). Return false if it doesn't exist.

Props UmeshSingla.
Fixes #17034.

#12 @johnjamesjacoby
10 years ago

Similar enough to #22413 to link here.

Note: See TracTickets for help on using tickets.