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

Use hitsPerPage as the value for $query->set( 'posts_per_page' ); in Algolia_Search::pre_get_posts() #43

Closed
richaber opened this issue Dec 17, 2019 · 1 comment
Assignees
Labels
bug Something isn't working enhancement New feature or request

Comments

@richaber
Copy link
Contributor

Is your feature request related to a problem? Please describe.
The Algolia_Search::pre_get_posts() method uses the posts_per_page option for the value of the hitsPerPage index search parameter.

The algolia_search_params filter allows you to modify the hitsPerPage value, but doing so throws pagination off, as posts_per_page is also used in a call to $query->set( 'posts_per_page', $posts_per_page ); in the same method.

Describe the solution you'd like
Use the value of hitsPerPage in the call to $query->set( 'posts_per_page', $params['hitsPerPage'] );, so that a filtered hitsPerPage value does not throw pagination off.

Describe alternatives you've considered
Hook into pre_get_posts with a custom function in theme, on a later priority, and $query->set( 'posts_per_page', $my_custom_hits_per_page_value );. I'm not convinced that would work, and it seems kinda gross, since we could just handle it gracefully in the Algolia_Search::pre_get_posts() method. We could also provide a filter for $posts_per_page but then we run the risk of $posts_per_page and hitsPerPage not matching.

Additional context
Some plugins and themes do not use the value of posts_per_page in their custom search pages. In those circumstances, site owners may experience confusing issues revolving around pagination. Asking them to filter hitsPerPage does not resolve their issues, again, due to the later use of posts_per_page in $query->set( 'posts_per_page', $posts_per_page );. See this WPORG support issue for additional context.

@richaber richaber self-assigned this Dec 17, 2019
@richaber richaber added enhancement New feature or request bug Something isn't working labels Dec 17, 2019
richaber added a commit that referenced this issue Dec 27, 2019
#43 Use filtered value of 'hitsPerPage' as 'posts_per_page' query param
@richaber
Copy link
Contributor Author

Merged PR #44

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant