Make WordPress Core

Opened 9 years ago

Last modified 5 years ago

#35820 new defect (bug)

WP_Query(array( 'p' => 0)) will return posts

Reported by: chiefalchemist's profile 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)

#1 @boonebgorges
9 years ago

  • Component changed from Database to Query
  • Milestone changed from Awaiting Review to Future Release

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 match 0 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:

  1. Unit tests describing the changed behavior
  2. A review of the plugin repo to see the circumstances in which people are passing 'p' => 0 to WP_Query. If it's widely used as a way to disable the p check, then we probably can't change it. (This is a good task for anyone wanting to help with the ticket.)
  3. Assuming it's not being widely exploited, we should drop it in at the very beginning of a dev cycle, with some related publicity, so we have time to see what breaks.

35820.diff is what the patch would look like.

Note: See TracTickets for help on using tickets.