WordPress.org

Make WordPress Core

Opened 11 months ago

Closed 11 months ago

Last modified 11 months ago

#51677 closed defect (bug) (wontfix)

Limit param not consistent between object query classes.

Reported by: keraweb Owned by:
Milestone: Priority: normal
Severity: normal Version:
Component: Query Keywords:
Focuses: Cc:

Description

When querying without limit for posts (posts_per_page param) you pass -1 as the limit parameter.
If you want to do the same for terms (number param) you need to pass 0.
These two options are apparently not both valid in both cases.

For consistency I'd say both -1 and 0 should be valid as a "no limit" query parameter in all cases.
Or at least the WP_Term_Query class should also accept -1 as the limiting param.

Change History (5)

This ticket was mentioned in Slack in #core by noisysocks. View the logs.


11 months ago

#2 @markparnell
11 months ago

  • Milestone Awaiting Review deleted
  • Resolution set to wontfix
  • Status changed from new to closed

Hi @keraweb, thanks for the report. We had a look and it's even stranger than it seems on the surface! Unfortunately with the way that the different values are treated right now, to change either query could potentially causing backwards compatibility issues with code that is relying on the existing behaviour. So as much as this is weird and frustrating it's not something that we can safely do anything about at this time.

#3 @keraweb
11 months ago

Hi @markparnell

And what about just allowing -1 as a number param value for no limit in WP_Term_Query? This shouldn't break backwards compatibility right?

Last edited 11 months ago by keraweb (previous) (diff)

#4 follow-up: @markparnell
11 months ago

@keraweb unfortunately it could. Right now WP_Term_Query runs absint() over the passed value, so -1 becomes 1. If anyone is (incorrectly) passing a negative value right now, changing it to return all results for -1 would alter the results they get.

You can see more detail on the discussion we had around this issue in the Slack archive

#5 in reply to: ↑ 4 @keraweb
11 months ago

Replying to markparnell:

If anyone is (incorrectly) passing a negative value right now, changing it to return all results for -1 would alter the results they get.

Are you saying WordPress even considers incorrect function usages for backwards compatibility?
Read through the Slack discussion and I have to say though I'm very much pro backwards compatibility, that seems a bit overdone to me..

Note: See TracTickets for help on using tickets.