• Hi,

    I added Infinite Scroll to my website, and I have set it to 20 posts page page. My archive loads, shows first 20 page, scroll down, and infinite scroll loads posts, again showing first 20 posts. If I load page 3 directly, scroll down, expecting page 4, again I get page 1.

    I have noticed in the code that JavaScript sets value for ‘offset’ and later in the query parsing for AJAX response, this is not used. And JavaScript sets page as 1 initially, and it is always sent as 1. So, either offset needs to be used, or page to be set to proper: current page + 1.

    Milan

    https://wordpress.org/plugins/jetpack/

Viewing 5 replies - 1 through 5 (of 5 total)
  • Plugin Author Jeremy Herve

    (@jeherve)

    Jetpack Mechanic 🚀

    Could you let me know how you added Infinite Scroll support to your theme? Could you also try to switch to one of the default themes for a few minutes, and let me know if you experience the same problem there?

    Thanks!

    Thread Starter Milan Petrovic

    (@gdragon)

    It works with default theme.

    I added support to my theme using this:

    add_theme_support('infinite-scroll', array(
      'type' => 'scroll',
      'container' => 'content',
      'footer' => false,
      'render' => 'my_category_render_loop',
      'posts_per_page' => 20
    ));

    Theme doesn’t have own loops, it is normal category archive loop with modified sorting (uses custom field), modification is done on pre_get_posts as it should be.

    I have debugged what is happening on each AJAX request, and in the Infinite Scroll query() method, page is never set, and offset is never used. JavaScript Infinite Scroll generates in page to get query parameters has ‘offset’ set to current page, and that is OK, and page is not set there, and AJAX always sends page as 1. I added one changes: to set page to current page in JS, and it is working. Why is offset page set and never used, I am not sure.

    Milan

    Plugin Author Jeremy Herve

    (@jeherve)

    Jetpack Mechanic 🚀

    it is normal category archive loop with modified sorting (uses custom field), modification is done on pre_get_posts as it should be.

    Could you paste the code you used here, so I can run some tests on my end?

    Thanks!

    Thread Starter Milan Petrovic

    (@gdragon)

    This is what is pre_get_posts function:

    function my_pre_get_posts($query) {
      $query->set('orderby', 'meta_value_num');
      $query->set('meta_key', 'event_date');
    }

    Milan

    Plugin Author Jeremy Herve

    (@jeherve)

    Jetpack Mechanic 🚀

    Could you try to add these parameters to Infinite Scroll as well, as explained here:
    https://wordpress.org/support/topic/jetpack-infinite-scroll-breaks-sort-order?replies=4#post-4738951

    Let me know if it helps.

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘Infinite Scroll first load returns always first page’ is closed to new replies.