#32453 closed defect (bug) (invalid)
add_meta_box callback receives Post Object with ID a String instead of an Integer
Reported by: | adiant | Owned by: | |
---|---|---|---|
Milestone: | Priority: | normal | |
Severity: | minor | Version: | 4.2.2 |
Component: | Options, Meta APIs | Keywords: | |
Focuses: | Cc: |
Description
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)
Change History (5)
#2
@
10 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.
Demonstration Plugin