[wp-hackers] WP_Query bug?
otto at ottodestruct.com
Wed May 9 22:47:04 UTC 2012
On Wed, May 9, 2012 at 4:41 PM, Robert Lusby <nanogwp at gmail.com> wrote:
> Just noticied that when running a custom WP_Query, setting:
> 'posts_per_page' => -1 & 'offset' => 1
> the offset will get ignored.
> Offset works fine if posts_per_page is any value other than -1.
> Thoughts? Bug? Or as -1 is meant to return everything, should it stay?
> Expected outcome was to run everything, except the first (e.g. everything
> offset by 1).
MySQL doesn't have a way to specify an offset with no maximum limit of
rows returned. So if you set posts_per_page to -1, then the nopaging
flag gets set to true, and no LIMIT clause is added to the query.
So, not "bug", just a limitation of the underlying database system.
If you want to get "all" posts with an offset, specify the
posts_per_page as a ludicrously high number instead. The MySQL
reference uses this exact approach with this example:
SELECT * FROM tbl LIMIT 95,18446744073709551615;
Which would be an offset of 96, and the posts_per_page as
18,446,744,073,709,551,615. Which is clearly insane, but should work.
I might pick a smaller number though. :)
More information about the wp-hackers