Open kipraske opened 6 years ago
Now that I have had a weekend to think about it a bit. Maybe you all can put a hook in there to determine which way we want to run the query. That way the folks that need is_main_query()
can have everything keep working the way that it used to, and I can use the old way for my old theme here. That way I can avoid forking Jetpack and everyone wins.
I'm having the same problem. On the homepage, I use pre_get_posts
to prevent some posts from showing on the homepage, but that filter runs on infinite scroll queries on the rest of the site too.
My code:
function filter_front_page_query( $query ) {
if ( ! is_admin() && $query->is_main_query() && $query->is_home() ) {
$do_not_duplicate = get_do_not_duplicate();
$query->set( 'post__not_in', $do_not_duplicate );
}
}
add_action( 'pre_get_posts', 'filter_front_page_query' );
Even if I change the priority, those posts get excluded from all infinite scroll queries.
This issue has been marked as stale. This happened because:
No further action is needed. But it's worth checking if this ticket has clear reproduction steps and it is still reproducible. Feel free to close this issue if you think it's not valid anymore — if you do, please add a brief explanation.
Steps to reproduce the issue
It appears that the changes that were made in tag 6.0 on lines 1263 to 1265 in modules/infinte-scroll/infinite-scroll.php broke one of our sites. The particular bug is that my conditional in a pre-get-posts hook that I have no longer works when we call $wp_query->query() after we make the object for some reason.
This is my condition in the pre-get-posts:
So when we are on the archive page for the post type "blog" we end up going into the first condition instead of the 2nd like I would expect. That is, the
array_key_exists( 'post_type', $wp_query->query )
is false, andis_home()
is true even though I am on the "blog" custom post type archive page.If we revert Jetpack to how it was in 5.9 everything works fine again.
So as far as steps go to reproduce
query
variable but not in thequery_vars
variableWhat I expected
I expected the query that jetpack infinite scroll uses to match the one that loads on the page
What happened instead
is_home()
call here in pre-get-posts is set to true even though we are on an archive. This causes us to pull the 3 post types defined in the code aboveblog
so we never go into the second if statement. Because wordpress doesn't think we are on an archive it assumes we are on the homepage.Conclusions
So this issue is mostly to say "pretty please can you change it back?", from the change log the reason for changing these lines in Jetpack is:
but as you can see here we are just calling
$wp_query->is_main_query()
from the global anyway. Of course, there is probably someone else out there whose site broke because it was the other way. Just let me know if you will fix this issue in jetpack or if I have to re-write the way that we handle the infinite scroll on our site