I am verifying my plugin with wordpress coding standard and php codesniffer but i do not know how to remove this issue:
Disabling pagination is prohibited in VIP context, do not set
| | `posts_per_page` to `-1` ever.
| | (WordPress.VIP.PostsPerPage.posts_per_page)
I alway use posts_per_page = -1 to get posts to get all posts, i do not know how to get all posts without this.
PHPCS with the WordPress plugin gives this error, for all of the following cases:
Why? Basically, if you disable paging, then you could run into serious performance issues if the query has the potential to return more results than your server (or client) could handle.
The rationale seems to be explained in this GitHub issue:
If you want to stop PHPCS from complaining about this, either fix the code to start using paging, or disable these particular checkes by including this code in your
phpcs.xml
file:Update for PHPCS WP version 1.0:
Version 1.0 no longer includes the
WordPress.VIP
policies any more, so you might not see this error if you upgrade it. See changelog.Just set ‘posts_per_page’ => PHP_INT_MAX,
That is what I’ve done and PHPCS is now happy 🙂