#39164 closed defect (bug) (invalid)
WP 4.7 broke get_post_type or requires an explicit integer value?
| Reported by: |
|
Owned by: | |
|---|---|---|---|
| Milestone: | Priority: | normal | |
| Severity: | normal | Version: | 4.7 |
| Component: | General | Keywords: | |
| Focuses: | Cc: |
Description
I just upgraded to WP 4.7, and suddenly code that uses get_post_type($id) stopped returning anything, and didn't throw an error either.
After trying a few things, I found that it would start working again if I changed my code from
get_post_type($id)
to
get_post_type(intval($id))
But I can't find anything in the docs about WP suddenly requiring explicit integer values. Anyone else seeing this?
Change History (3)
#2
@
9 years ago
- Milestone Awaiting Review deleted
- Resolution set to invalid
- Status changed from new to closed
This was an intentional change to get_post() in 4.7 - passing an invalid parameter may have previously returned a result, but it could've been an incorrect resource, for example, a value being cast to a numeric 1 and fetching from the incorrect post.
get_post( 123 ) is the same as get_post( '123' ) but not the same as get_post( " 123 " ) (Which now fails) IMHO, so I agree with the change, especially in this case.
For reference, see #37738
UPDATE
So, using trim instead of intval works too.
And checking $id
(preg_match('/\s/',$id))shows that it had a space. But oddly, this worked just fine in WP 4.6, so something must have changed to make that less forgiving in WP 4.7