• Resolved stueynet

    (@stueynet)


    The main issue is that we need to start the jetpack infinite scroll loop at post #4 instead of the first one. So to do so I have done:

    function vc_offset_posts( $query ) {
    	if ( is_admin() || ! $query->is_main_query() )
    		return;
    	if ( $query->is_home() && $query->is_main_query() ) {
    		$query->set( 'offset', 3 );
    		return;
    	}
    }
    add_action( 'pre_get_posts', 'vc_offset_posts', 10 );

    Unfortunately what this does is cause every new click of the load button to load the same set of posts. So on page load we get:

    4,5,6,7,8,9

    then you click and get

    10,11,12,13,14,15

    But if you click again you continue to get

    10,11,12,13,14,15

    Have tested this ad infinitum and it only happens with the offset filter. Other filters don’t cause a problem including posts_per_page etc…

    Would love some help.

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

Viewing 6 replies - 1 through 6 (of 6 total)
  • Thread Starter stueynet

    (@stueynet)

    I have also tried checking the paged property but no luck as follows:

    function vc_offset_posts( $query ) {
            global $wp_query;
    	if ( is_admin() || ! $query->is_main_query() )
    		return;
            if ($wp_query->query_vars['paged'] > 0)
                    return;
    	if ( $query->is_home() && $query->is_main_query() ) {
    		$query->set( 'offset', 3 );
    		return;
    	}
    }
    add_action( 'pre_get_posts', 'vc_offset_posts', 10 );
    Plugin Author Jeremy Herve

    (@jeherve)

    Jetpack Mechanic 🚀

    Could you try to use the infinite_scroll_query_args filter to add the offset to Infinite Scroll, as explained here:
    https://wordpress.org/support/topic/jetpack-infinite-scroll-breaks-sort-order?replies=4&view=all

    That should help!

    Thread Starter stueynet

    (@stueynet)

    Thanks Jeremy. That works. To be specific I stil’ have the above, but then also do:

    function jetpack_infinite_scroll_query_args( $args ) {
    	$args['offset']   = null;
    	return $args;
    }
    add_filter( 'infinite_scroll_query_args', 'jetpack_infinite_scroll_query_args' );
    Thread Starter stueynet

    (@stueynet)

    Astounded that this filter is nowhere to be found in the Jetpack Docs.

    Plugin Author Jeremy Herve

    (@jeherve)

    Jetpack Mechanic 🚀

    Glad to hear you’re all set!

    Astounded that this filter is nowhere to be found in the Jetpack Docs.

    That’s indeed not easy to find, unless you know what you’re looking for. Sorry about that!

    We’ve just released our new code reference, and the infinite_scroll_query_args filter is listed there, but we still have some work to do to add examples to the docs, and add links to some of the most useful filters to each support doc. We’re working on that! Hopefully Google will start returning more and more code reference pages as well 🙂

    Until that happens, I’ve added a new section to the Infinite Scroll support documentation to mention that filter.

    Thanks for the feedback!

    Thread Starter stueynet

    (@stueynet)

    Thanks Jeremy! Great job.

Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘Using "offset" causes loaded posts to repeat endlessly’ is closed to new replies.