Automattic / Automattic/jetpack
Infinite Scroll: Pages with custom query using category__in or tag__in don't paginate properly
- Dominant language
- PHP
- Stars
- 1.8k
- Forks
- 898
- Avg merge
- 1d 18h
- Merged PRs (30d)
- 774
Description
#### What I expected
When I set a custom query using `pre_get_posts` action with multiple categories or tags, for example:
``` php
function my_custom_query( $query ) {
if( $query->is_tag() ) {
$query->set( 'category__in', array( 42, 43, 44 ) );
}
}
add_action( 'pre_get_posts', 'my_custom_query' );
```
The posts that was rendered in page was correct filtered by categories 42, 43, 44.
When I click or scroll to load more posts through infinite scroll I expect the posts that were added to page are using 42, 43, 44 categories.
#### What happened instead
When I click or scroll through infinite scroll, the posts that were added to page is only from category 42, the first category which was assigned at `pre_get_posts` filter.
#### Steps to reproduce the issue
- create some categories at wp-admin;
- create some posts with this categories;
- setup a theme with `pre_get_posts` action and set a `category__in` with theses categories ids;
- check that the displayed posts was from these categories;
- paginate through infinite scroll;
- posts that was added by infinite scroll was only from first category assigned at `pre_get_posts`.
#### More About
If you inspect javascript global variable `infiniteScroll` at page, it has the `category__in` array with correct ids assigned at `pre_get_posts`. But the key `category_name` and `cat` in `infiniteScroll.settings.query_args` has only the first category slug and id.
Apparently this was correct, because it was used for backward compatibility, as was being explained [in this core ticket](https://core.trac.wordpress.org/ticket/30846#comment:2).
But I think infinite scroll query was only considering the category at `cat` or `category_name` at query_vars and ignoring `category__in`.
I did a workaround using `infinite_scroll_query_args` action, but i think infinite scroll should work as is in wordpress rendered page.
I don't tested with `tag__in` filter, but I think that has the same issue.
I was using:
- https://github.com/Automattic/vip-quickstart vagrant image
- Wordpress version 4.6-alpha-37651
- Jetpack 4.0.2
- PHP 5-5.6
- Ubuntu 12.04
Contributor guide
Assessment
This issue has not been assessed yet.