Directory

`WP_Query` pagination parameters `posts_per_page` description · Issue #918 · WordPress/Documentation-Issue-Tracker · GitHub
Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WP_Query pagination parameters posts_per_page description #918

Closed
crstauf opened this issue Jul 3, 2023 · 2 comments
Closed

WP_Query pagination parameters posts_per_page description #918

crstauf opened this issue Jul 3, 2023 · 2 comments
Assignees
Labels
code reference Issues for Code Reference portal of DevHub [Status] Done Issue is completed

Comments

@crstauf
Copy link

crstauf commented Jul 3, 2023

Issue Description

The statement “To reimpose the limit, try using the ‘post_limits’ filter, or filter ‘pre_option_posts_per_rss’ and return -1” is unfortunately not correct. If you return -1 for ‘pre_option_posts_per_rss’, this value will be inserted directly at the LIMIT clause of the SQL query i.e. it will say something like LIMIT 0,-1 in the SQL query.
This leads to an SQL error so that no result is returned. With this filter it is mandatory that a number > 0 is returned. In case of doubt, you should use the PHP constant PHP_INT_MAX so that on most cases all entries are outputted.
It is extremely unlikely that there are more than 2147483647 (32-bit OS) or 9223372036854775807 (64-bit OS), but if there are, the return value would have to be increased accordingly.

Reported by mumbomedia via User Contributed Notes.

URL of the Page with the Issue

https://developer.wordpress.org/reference/classes/wp_query/#pagination-parameters

Section of Page with the issue

Pagination Parameters

Why is this a problem?

Causes an SQL error.

Suggested Fix

Remove or rephrase the sentence on how to change the post limit for feeds.

To reimpose the limit, try using the ‘post_limits’ filter, or filter ‘pre_option_posts_per_rss’ and return [a large number].

@crstauf crstauf added the [Status] To do Issue marked as Todo label Jul 3, 2023
@stevenlinx stevenlinx added the code reference Issues for Code Reference portal of DevHub label Jul 31, 2023
@stevenlinx stevenlinx self-assigned this Jul 31, 2023
@github-actions
Copy link

Heads up @zzap - the "code reference" label was applied to this issue.

@github-actions github-actions bot added [Status] In progress Issue is in progress and removed [Status] To do Issue marked as Todo labels Jul 31, 2023
@stevenlinx
Copy link
Member

Thanks for filing.

I've revise the sentence to be:
To reimpose the limit, try using the post_limits filter, or filter pre_option_posts_per_rss and return a very large number (if you want to return all posts) such as PHP constant PHP_INT_MAX so that on most cases all entries are outputted.

@github-actions github-actions bot added [Status] Done Issue is completed and removed [Status] In progress Issue is in progress labels Oct 2, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
code reference Issues for Code Reference portal of DevHub [Status] Done Issue is completed
Projects
None yet
Development

No branches or pull requests

2 participants