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

Fix negative offset on hierarchical post types #2511

Merged
merged 1 commit into from
Dec 14, 2021

Conversation

tfrommen
Copy link
Contributor

@tfrommen tfrommen commented Dec 9, 2021

Description of the Change

This PR ensures that the from argument (offset) for post search requests is not negative. This will happen on hierarchical post types on pages other than the first.

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).

Alternate Designs

n/a

Benefits

Working pagination on hierarchical post types such as the default page. 🎉

Possible Drawbacks

n/a

Verification Process

  1. Go to Pages in the admin: /wp-admin/edit-php?post_type=page
  2. Search for a word or phrase where you have lots of posts that include this.
  3. Use pagination buttons to navigate to, say, page 3.
  4. Without this change, this will result in a request error for Elasticsearch. With this change, everything is working as expected, and you can navigate to any page you like.

Checklist:

  • I have read the CONTRIBUTING document.
  • My code follows the code style of this project.
  • My change requires a change to the documentation.
  • I have updated the documentation accordingly.
  • I have added tests to cover my change.
  • All new and existing tests passed.

Applicable Issues

#2480

Changelog Entry

  • Fix broken search pagination on hierarchical post types

@mckdemps mckdemps added this to the 3.6.6 milestone Dec 14, 2021
@felipeelia felipeelia linked an issue Dec 14, 2021 that may be closed by this pull request
@felipeelia felipeelia merged commit 287af71 into 10up:develop Dec 14, 2021
@tfrommen tfrommen deleted the patch-2 branch December 15, 2021 00:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

BUG: Broken Search Pagination on Hierarchical Post Types
3 participants