Opened 9 years ago
Last modified 5 years ago
#35820 new defect (bug)
WP_Query(array( 'p' => 0)) will return posts
Reported by: | ChiefAlchemist | Owned by: | |
---|---|---|---|
Milestone: | Priority: | normal | |
Severity: | normal | Version: | 4.4.2 |
Component: | Query | Keywords: | |
Focuses: | Cc: |
Description
Long to short, I was presuming that if the $args were such that no rows exist then WP_Query would return nothing.
Not so.
If by chance, 'p' => 0, you do get results.
Perhaps the 0 is interpreted as false? Even so, an ID == false should return no row, yes? Or one might argue "well, that query doesn't make sense. it's not really valid." again, all the more reason to return nothing.
Change History (1)
Note: See
TracTickets for help on using
tickets.
I agree that it's counterintuitive, and that, in theory,
'p' => 0
should return no results.However, it's likely that such a change would introduce backward compatibility concerns. See #35090 and [36381] for a similar issue, where it was quickly discovered that people were passing
0
to disable the parameter, rather than to match0
as a value.In order to consider a change like this (which applies equally to
page_id
,year
,monthnum
,day
,w
,paged
, and maybe others), we need a couple things:'p' => 0
toWP_Query
. If it's widely used as a way to disable thep
check, then we probably can't change it. (This is a good task for anyone wanting to help with the ticket.)35820.diff is what the patch would look like.