#28631 closed defect (bug) (fixed)
WP_User_Query should support -1 for the number parameter
Reported by: | mordauk | Owned by: | wonderboymusic |
---|---|---|---|
Milestone: | 4.4 | Priority: | normal |
Severity: | normal | Version: | 4.0 |
Component: | Users | Keywords: | has-patch |
Focuses: | Cc: |
Description
In order to be consistent with WP_Query, I think WP_User_Query should accept -1
as a valid value for the number
parameter.
If you want to perform a query that returns all posts, you pass -1
for posts_per_page
to WP_Query.
If you try to do this with WP_User_Query, however, you get an SQL syntax error:
WordPress database error: [You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '-1' at line 2] SELECT SQL_CALC_FOUND_ROWS wp_users.* FROM wp_users INNER JOIN wp_usermeta ON (wp_users.ID = wp_usermeta.user_id) WHERE 1=1 AND ( (CAST(wp_usermeta.meta_value AS CHAR) LIKE '%\"pending\\_vendor\"%') ) AND (wp_usermeta.meta_key = 'wp_capabilities' ) ORDER BY user_login ASC LIMIT -1
LIMIT
can't be -1
in SQL.
I'd expect both of these to return the same results:
$query = new WP_User_Query( array( 'number' => -1 ) ); $query = new WP_User_Query( array( 'number' => 99999999 ) );
Attachments (4)
Change History (17)
#2
@
10 years ago
28631.diff looks good to me.
#3
@
10 years ago
- Keywords needs-unit-tests added
- Milestone changed from Awaiting Review to Future Release
needs-unit-tests :-)
#5
@
10 years ago
28631-2.diff is a refreshed patch for the /src/
directory.
28631-tests-2.diff adds an additional test that checks for proper counts when passing the number
parameter as 12
, 10
, and -1
.
Note: See
TracTickets for help on using
tickets.
WP_Query has a
nopaging
argument that's true or false which defines whether we add or not the LIMIT statement, a simple check for a positive number could probably solve that. I'm not sure if aintval
call should be used as well to prevent floating point numbers, but that quick check ignores the limits for all non-negative numbers and zero.