Title: Duplicate posts when using Infinite loop and offset
Last modified: August 21, 2016

---

# Duplicate posts when using Infinite loop and offset

 *  Resolved [Christine Rondeau](https://wordpress.org/support/users/crondeau/)
 * (@crondeau)
 * [12 years, 8 months ago](https://wordpress.org/support/topic/duplicate-posts-when-using-infinite-loop-and-offset/)
 * I was trying to get jetpack’s infinite loop on my site and it’s working just 
   fine, but of course the design specified that the first 2 posts have a slightly
   different design, so I thought I could just use a wp_query like so:
 *     ```
       <?php
               $loop = new WP_Query( array(
                 'ignore_sticky_posts'  => true,
                 'offset' => 2,
               ));
             while ( $loop->have_posts() ) : $loop->the_post(); 
   
                 get_template_part( 'content' );
   
           endwhile;  wp_reset_query(); ?>
       ```
   
 * That’s all great and infinite loop works, but the next 2 posts are repeats of
   the last two. I found this thread – [http://wordpress.org/support/topic/custom-queries-and-how-to-avoid-jetpack-infinite-scroll-to-duplicate-post?replies=5](http://wordpress.org/support/topic/custom-queries-and-how-to-avoid-jetpack-infinite-scroll-to-duplicate-post?replies=5)
   
   and thought that it might be related, but since it’s 5 months old, I thought 
   I would check.
 * Is jetpack’s status still the same? If not any idea how this could be achieved?
   I tried using a counter as well instead of offset, but no joy…
 * PS: I love jetpack by the way… 🙂
 * [http://wordpress.org/plugins/jetpack/](http://wordpress.org/plugins/jetpack/)

Viewing 15 replies - 1 through 15 (of 22 total)

1 [2](https://wordpress.org/support/topic/duplicate-posts-when-using-infinite-loop-and-offset/page/2/?output_format=md)
[→](https://wordpress.org/support/topic/duplicate-posts-when-using-infinite-loop-and-offset/page/2/?output_format=md)

 *  Plugin Author [Jeremy Herve](https://wordpress.org/support/users/jeherve/)
 * (@jeherve)
 * Jetpack Mechanic 🚀
 * [12 years, 8 months ago](https://wordpress.org/support/topic/duplicate-posts-when-using-infinite-loop-and-offset/#post-4047623)
 * I’m afraid we haven’t found any solution to this problem yet. We’ve been working
   on improving Infinite Scroll to change how we capture arguments from the main
   query, but we still need to work on this.
 * I’ll post again here as soon as we have a solution!
 *  Thread Starter [Christine Rondeau](https://wordpress.org/support/users/crondeau/)
 * (@crondeau)
 * [12 years, 8 months ago](https://wordpress.org/support/topic/duplicate-posts-when-using-infinite-loop-and-offset/#post-4047636)
 * Glad i checked in with you instead of trying to get this to work.
    I think that
   we’ll just keep the design simple for now.
 * Thanks Jeremy
 *  [kkalbat](https://wordpress.org/support/users/kkalbat/)
 * (@kkalbat)
 * [12 years, 5 months ago](https://wordpress.org/support/topic/duplicate-posts-when-using-infinite-loop-and-offset/#post-4047803)
 * The question is: Is there a solid plan to implement wp_query for infinite scrolling,
   or should we just try and implement by ourselves?
 * It would also be nice to post some updates on what features are being worked 
   on right now and when they are expected to be rolled out.
 *  Plugin Author [Jeremy Herve](https://wordpress.org/support/users/jeherve/)
 * (@jeherve)
 * Jetpack Mechanic 🚀
 * [12 years, 5 months ago](https://wordpress.org/support/topic/duplicate-posts-when-using-infinite-loop-and-offset/#post-4047804)
 * [@kkalbat](https://wordpress.org/support/users/kkalbat/) I replied to your question
   [here](http://wordpress.org/support/topic/custom-queries-and-how-to-avoid-jetpack-infinite-scroll-to-duplicate-post?replies=11#post-5002902).
 * > It would also be nice to post some updates on what features are being worked
   > on right now and when they are expected to be rolled out.
 * If you’re interested in the things we’re working on at the moment, and if you
   want to help us test all the new features, you might be a good candidate for 
   our Beta Group! [Send us an email!](http://jetpack.me/contact-support/)
 * You can also follow our progress by looking at opened tickets [here](http://plugins.trac.wordpress.org/query?status=assigned&status=new&status=reopened&component=jetpack&group=type&col=id&col=summary&col=status&col=owner&col=type&col=priority&col=severity&order=priority).
   You can also [contribute](http://jetpack.me/contribute/) and submit patches there.
 * The [development log](http://plugins.trac.wordpress.org/log/jetpack/) is also
   a good way to keep an eye on what’s happening with Jetpack.
 * I hope this helps.
 *  [kkalbat](https://wordpress.org/support/users/kkalbat/)
 * (@kkalbat)
 * [12 years, 5 months ago](https://wordpress.org/support/topic/duplicate-posts-when-using-infinite-loop-and-offset/#post-4047805)
 * Thank Jeremy, I would love to join the group. I will send an email soon.
 *  [maxgx](https://wordpress.org/support/users/maxgx/)
 * (@maxgx)
 * [12 years, 1 month ago](https://wordpress.org/support/topic/duplicate-posts-when-using-infinite-loop-and-offset/#post-4047818)
 * hi Jeremy
    with regard to your statement [“Infinite Scroll now supports a greater range of queries”](http://wordpress.org/support/topic/custom-queries-and-how-to-avoid-jetpack-infinite-scroll-to-duplicate-post),
   is it possible for you to suggest how we can make use of IS support of queries
   to implement a solution for the questions above?
 * i too have a custom query for a custom loop to exclude certain posts and also
   interrupt and start the loop further down the page using offset to show the rest,
   but when IS kicks in, it’s showing the same posts shown above.
 * also, on the same thread g10r3 mentions a “featured content” module in jetpack
   which could be used to achieve this: where exactly is that? i cannot see it…
 * any chance to get some hints?
 *  Plugin Author [Jeremy Herve](https://wordpress.org/support/users/jeherve/)
 * (@jeherve)
 * Jetpack Mechanic 🚀
 * [12 years, 1 month ago](https://wordpress.org/support/topic/duplicate-posts-when-using-infinite-loop-and-offset/#post-4047819)
 * > is it possible for you to suggest how we can make use of IS support of queries
   > to implement a solution for the questions above?
 * We’ve made some changes to IS in [r777844-plugins](https://plugins.trac.wordpress.org/changeset/777844).
   That changeset introduces 2 new filters, `infinite_scroll_allowed_vars` and `
   infinite_scroll_query_args`.
 * You can use create functions to add the new arguments and variables you use in
   your custom query, and hook them into the 2 filters, using a priority higher 
   than the default (10), so that the filters get applied after our functions `inject_query_args()`
   and `allowed_query_vars`.
 * I hope this helps.
 *  [maxgx](https://wordpress.org/support/users/maxgx/)
 * (@maxgx)
 * [12 years, 1 month ago](https://wordpress.org/support/topic/duplicate-posts-when-using-infinite-loop-and-offset/#post-4047820)
 * thanks a lot for the reply Jeremy! … although i’ve been banging my head against
   this brick-wall since…
    i’m not that strong in coding, so i’m finding difficult
   to implement what’s needed. i wonder if i can abuse your kindness some more.
 * this is my first custom query:
 *     ```
       <?php
       $custom_args=array(
       	'posts_per_page'         => '2'
       ); // END $args
       $custom_query = null; // clear the query variable
       $custom_query = new WP_Query($custom_args);
        ?>
       		<?php if ( $custom_query->have_posts() ) : ?>
       			<?php while ( $custom_query->have_posts() ) : $custom_query->the_post(); ?>
       				<?php get_template_part( 'content', get_post_format() ); ?>
       			<?php endwhile; ?>
       		<?php else : ?>
       			... something else ...
       		<?php endif; // end have_posts() check ?>
       		<?php wp_reset_query(); ?>
       ```
   
 * after that, i have a sidebar call, then i start again with another loop, offsetting
   it from 2:
 *     ```
       <?php
       $custom2_args=array(
       	'offset'                 => '2'
       ); // END $args
       $custom2_query = null; // clear the query variable
       $custom2_query = new WP_Query($custom2_args);
        ?>
       		<?php if ( $custom2_query->have_posts() ) : ?>
       			<?php while ( $custom2_query->have_posts() ) : $custom2_query->the_post(); ?>
       				<?php get_template_part( 'content', get_post_format() ); ?>
       			<?php endwhile; ?>
       		<?php else : ?>
       			... something else ...
       		<?php endif; // end have_posts() check ?>
       		<?php wp_reset_query(); ?>
       ```
   
 * should i move the lot into functions in functions.php? and how do i hook into
   the IS filters?
 *  Plugin Author [Jeremy Herve](https://wordpress.org/support/users/jeherve/)
 * (@jeherve)
 * Jetpack Mechanic 🚀
 * [12 years, 1 month ago](https://wordpress.org/support/topic/duplicate-posts-when-using-infinite-loop-and-offset/#post-4047821)
 * Could you try to use something like this instead, to avoid making changes to 
   your loop?
    [http://wordpress.org/support/topic/insert-sidebars-between-posts-how-do-i-code-this-in-my-indexphp?replies=3#post-3550028](http://wordpress.org/support/topic/insert-sidebars-between-posts-how-do-i-code-this-in-my-indexphp?replies=3#post-3550028)
 *  [maxgx](https://wordpress.org/support/users/maxgx/)
 * (@maxgx)
 * [12 years, 1 month ago](https://wordpress.org/support/topic/duplicate-posts-when-using-infinite-loop-and-offset/#post-4047822)
 * fantastic! that’s what i was looking for!
    and for hiding posts from IS i’m setting
   them as sticky, that’s working great too! thanks a lot Jeremy!
 *  [maxgx](https://wordpress.org/support/users/maxgx/)
 * (@maxgx)
 * [12 years, 1 month ago](https://wordpress.org/support/topic/duplicate-posts-when-using-infinite-loop-and-offset/#post-4047823)
 * damn! too quick to sing victory…
 * i’m trying to exclude sticky posts from the main loop.
 * if i use a custom query to exclude stickies, IS does not recognise it. clicking
   on “older posts” (by the way, [this code](https://gist.github.com/jeherve/6177741)
   seems to have no effect on the wordings) shows a list of posts starting from 
   the first (with sticky post excluded) as per standard loop.
 * i thought of using a function to manipulate the query for the main loop, intercepting
   it earlier (maybe?):
 *     ```
       function nosticky_home_loop( $query ) {
       	if ( $query->is_home() && $query->is_main_query() ) {
       		$query->set( 'post__not_in', get_option( 'sticky_posts' ) );
       	}
       }
       add_action( 'pre_get_posts', 'nosticky_home_loop' );
       ```
   
 * but even this is not recognised by IS…
 *  Plugin Author [Jeremy Herve](https://wordpress.org/support/users/jeherve/)
 * (@jeherve)
 * Jetpack Mechanic 🚀
 * [12 years, 1 month ago](https://wordpress.org/support/topic/duplicate-posts-when-using-infinite-loop-and-offset/#post-4047824)
 * > by the way, this code seems to have no effect on the wordings
 * Try adding `is_front_page` to the list of conditionals.
 * > i thought of using a function to manipulate the query for the main loop, intercepting
   > it earlier (maybe?):
 * How about something like this?
 * [https://gist.github.com/jeherve/9739690](https://gist.github.com/jeherve/9739690)
 *  [maxgx](https://wordpress.org/support/users/maxgx/)
 * (@maxgx)
 * [12 years, 1 month ago](https://wordpress.org/support/topic/duplicate-posts-when-using-infinite-loop-and-offset/#post-4047825)
 * `$query->set( 'ignore_sticky_posts', true );`
    only sets the query to treat sticky
   in the same way as other posts in the main loop. the problem with duplicating
   content seems to stay though: when i hit the “older posts” link, it starts with
   the first non-sticky post from the main loop again.
 * replacing it with
    `$query->set( 'post__not_in', get_option( 'sticky_posts' ));`
   removes them from the loop, but has the duplicate problem too.
 * it seems that IS doesn’t like whenever/however the standard query is “retouched”
 *  Plugin Author [Jeremy Herve](https://wordpress.org/support/users/jeherve/)
 * (@jeherve)
 * Jetpack Mechanic 🚀
 * [12 years, 1 month ago](https://wordpress.org/support/topic/duplicate-posts-when-using-infinite-loop-and-offset/#post-4047826)
 * hm. That’s annoying. Could you try to add `post__not_in` to the list of allowed
   query args, like so:
 * [https://gist.github.com/jeherve/2541d2eef8231507d299](https://gist.github.com/jeherve/2541d2eef8231507d299)
 * Let me know if it helps.
 *  [maxgx](https://wordpress.org/support/users/maxgx/)
 * (@maxgx)
 * [12 years, 1 month ago](https://wordpress.org/support/topic/duplicate-posts-when-using-infinite-loop-and-offset/#post-4047827)
 * no, that doesn’t seem to work either.
 * these are the functions now, in that order (i tried reversing):
 *     ```
       // Add post__not_in to IS query args
       function jeherve_is_allowed_vars( $vars ) {
       	$vars[] = 'post__not_in';
       	return $vars;
       }
       add_filter( 'infinite_scroll_allowed_vars', 'jeherve_is_allowed_vars' );
   
       // Customize the loop on home page only
       function jeherve_custom_home_query( $query ) {
       	if ( ! $query->is_main_query() )
       		return;
       	if ( ! $query->is_home() || ! $query->is_front_page() || is_admin() )
       		return;
       	$query->set( 'post__not_in', get_option( 'sticky_posts' ) );
       }
       add_filter( 'pre_get_posts', 'jeherve_custom_home_query' );
       ```
   

Viewing 15 replies - 1 through 15 (of 22 total)

1 [2](https://wordpress.org/support/topic/duplicate-posts-when-using-infinite-loop-and-offset/page/2/?output_format=md)
[→](https://wordpress.org/support/topic/duplicate-posts-when-using-infinite-loop-and-offset/page/2/?output_format=md)

The topic ‘Duplicate posts when using Infinite loop and offset’ is closed to new
replies.

 * ![](https://ps.w.org/jetpack/assets/icon.svg?rev=2819237)
 * [Jetpack - WP Security, Backup, Speed, & Growth](https://wordpress.org/plugins/jetpack/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/jetpack/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/jetpack/)
 * [Active Topics](https://wordpress.org/support/plugin/jetpack/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/jetpack/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/jetpack/reviews/)

## Tags

 * [duplicate](https://wordpress.org/support/topic-tag/duplicate/)
 * [infinite loop](https://wordpress.org/support/topic-tag/infinite-loop/)

 * 22 replies
 * 4 participants
 * Last reply from: [Jeremy Herve](https://wordpress.org/support/users/jeherve/)
 * Last activity: [12 years, 1 month ago](https://wordpress.org/support/topic/duplicate-posts-when-using-infinite-loop-and-offset/page/2/#post-4047840)
 * Status: resolved