Make WordPress Core

Opened 9 years ago

Closed 9 years ago

Last modified 9 years ago

#32453 closed defect (bug) (invalid)

add_meta_box callback receives Post Object with ID a String instead of an Integer

Reported by: adiant's profile adiant Owned by:
Milestone: Priority: normal
Severity: minor Version: 4.2.2
Component: Options, Meta APIs Keywords:
Focuses: Cc:


The Post Object received by the Callback Function specified in the add_meta_box function delivers the correct value for ID, but the Type is String, not Integer.

The attached Plugin demonstrates the problem when in the Edit Page Admin panel.

Attachments (1)

jonradio-test.php (445 bytes) - added by adiant 9 years ago.
Demonstration Plugin

Download all attachments as: .zip

Change History (5)

9 years ago

Demonstration Plugin

#1 @adiant
9 years ago

  • Severity changed from normal to minor

#2 @dd32
9 years ago

Unfortunately this is a compatibility thing - All integers from the database are delivered to WordPress as numeric strings, not ints.

Changing the fields to be ints can unfortunately introduce compatibility issues, see #22324 and #22324 for some details on that.

Worth noting here, that you should always expect a numeric string OR integer for post ID's for maximum compatibility.

For example, with the provided code, on a new-page view you'll see it as an int, but on an edit you'll see it as a numeric string.

#3 @adiant
9 years ago

  • Resolution set to invalid
  • Status changed from new to closed

I agree with your reasoning and will try to update the Codex to make that clear.

#4 @johnbillion
9 years ago

  • Milestone Awaiting Review deleted
Note: See TracTickets for help on using tickets.