Wordpress loop problem: Multiple loops, index.php and is_paged causing duplicate posts on next page

I'm not sure if what I'm experiencing is a result of a bug (due to the recent upgrade to 3.1.2) or poor coding. Ever since I upgraded to version 3.1.2 I've been experiencing a problem with two loops on my index page.

Here's what I've got for my index page:

?php
    if ( ! is_paged()  is_front_page() ) {

    echo 'h6 class="sec1 title"FEATURE/h6';
    $sticky = get_option( 'sticky_posts' );

         if ( isset( $sticky[0] ) ) {
            $args = array(
                'posts_per_page' = 3,
                'post__in'  = $sticky,
                'ignore_sticky_posts' = 1);

            $featured_query = new WP_query( $args );
            while ($featured_query-have_posts() ) :
            $featured_query-the_post();

            get_template_part( 'content', 'featured' );

            endwhile;
        } // endif sticky
    } // endif is_paged
    ?

    ?php
        $sticky = get_option( 'sticky_posts' );
        echo 'h6 class="sec1 title"LATEST ARTICLES/h6';
        $paged = get_query_var( 'paged' ) ? get_query_var( 'paged' ) : 1;
        $query_args = array(
            'posts_per_page' = 10,
            'paged' = $paged,
            'post__not_in' = $sticky
            );

        query_posts($query_args);
        if (have_posts() ) :
        while (have_posts() ) :
        the_post();

        get_template_part( 'content', get_post_format() );
    ?

    !--?php trackback_rdf(); ?--

    ?php endwhile; else: ?

    div class="box"
        p
            ?php _e( 'Sorry, no posts matched your criteria.' ); ?
        /p
    /div

    ?php endif; ?

// Navigation comes over here

Say for example the first loop (sticky posts) - which IS NOT paged, yields 3 posts, and the second loop (all other posts) - which IS paged, yields 10 posts. The problem I'm experiencing is that when I move to the next page, the last 3 posts from the second loop on page 1 get repeated at the the top of page 2.


Note: The first loop is only on page 1, and doesn't get repeated on the second page, which is what I intended.

Note 2: I assume that the second loop is considering - in some odd way, the posts from the first loop as one of its own. But it still shows 10 posts on the first page + 3 posts from the first loop.


So in essence its:

PAGE 1:

Loop 1: 3 posts (3 unique posts)

Loop 2: 10 posts (10 unique posts)

PAGE 2:

Loop 1: Doesn't execute - as intended, due to ( ! is_paged() )

Loop 2: 10 posts (7 unique, 3 duplicated from the last 3 (from the second loop) on the first page)

So this is what I tried: I removed the ( ! is_paged() is_front_page ) condition along with the entire first loop, and the problem got resolved.

What am I doing wrong?

Topic paged loop pagination query-posts customization Wordpress

Category Web


I tried reverting back to the older version 3.0.x, but the problem remained the same.

The answer can be found here:

https://stackoverflow.com/questions/5843214/wordpress-loop-problem-multiple-loops-index-php-and-is-paged-causing-duplicate/5853514#5853514

About

Geeks Mental is a community that publishes articles and tutorials about Web, Android, Data Science, new techniques and Linux security.