You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Describe the bug
When searching a hierarchical post type in the admin, for example, Pages (/wp-admin/edit-php?post_type=page), the pagination is broken. This is becacuse of a combined bug in WordPress in ElasticPress.
Steps to Reproduce
Go to Pages in the admin: /wp-admin/edit-php?post_type=page
Search for a word or phrase where you have lots of posts that include this.
Use pagination buttons to navigate to, say, page 3.
This will result in a request error for Elasticsearch.
Expected behavior
Pagination when searching hierarchical post types should just work.
Screenshots
Environment information
(This is irrelevant because the two places in WordPress and ElasticPress code have been introduced years and years ago, see further down.)
Additional context
The reason for this issue is the from argument in the query, which is -2 (for page 3).
Now, with posts_per_page being -1, this will lead to -1 * ( PAGE - 1 ), which is the following:
Page 2: -1
Page 3: -2
Page 4: -3
...
Negative from values will lead to a null pointer exception, and thus a request error.
I think a fix for this would be to ensure that from is greater or equal to 0. That means, if posts_per_page is -1, just set from to 0, and it should all work. The actual pagination (i.e., showing the correct posts from all the posts fetched) will then be done by WordPress anyway.
The text was updated successfully, but these errors were encountered:
Hi @tfrommen, thanks for opening this issue! I'm able to reproduce the problem and your suggested fix seems to work fine. Do you have the availability to create a PR with that?
Describe the bug
When searching a hierarchical post type in the admin, for example, Pages (
/wp-admin/edit-php?post_type=page
), the pagination is broken. This is becacuse of a combined bug in WordPress in ElasticPress.Steps to Reproduce
/wp-admin/edit-php?post_type=page
Expected behavior
Pagination when searching hierarchical post types should just work.
Screenshots
Environment information
(This is irrelevant because the two places in WordPress and ElasticPress code have been introduced years and years ago, see further down.)
Additional context
The reason for this issue is the
from
argument in the query, which is-2
(for page 3).This is because ElasticPress uses
posts_per_page
to calculate the offset,POSTS_PER_PAGE * ( PAGE - 1 )
. For hierarchical post types, however, this value is overwritten to-1
by WordPress (most probably to fetch all posts so that posts to be shown on the current page that have a parent can be listed with their parent post).Now, with
posts_per_page
being-1
, this will lead to-1 * ( PAGE - 1 )
, which is the following:-1
-2
-3
Negative
from
values will lead to a null pointer exception, and thus a request error.I think a fix for this would be to ensure that
from
is greater or equal to0
. That means, ifposts_per_page
is-1
, just setfrom
to0
, and it should all work. The actual pagination (i.e., showing the correct posts from all the posts fetched) will then be done by WordPress anyway.The text was updated successfully, but these errors were encountered: