OiO.lk Community platform!

Oio.lk is an excellent forum for developers, providing a wide range of resources, discussions, and support for those in the developer community. Join oio.lk today to connect with like-minded professionals, share insights, and stay updated on the latest trends and technologies in the development field.
  You need to log in or register to access the solved answers to this problem.
  • You have reached the maximum number of guest views allowed
  • Please register below to remove this limitation

Wordpress Multiple loops on category template duplicate posts.

  • Thread starter Thread starter Adam
  • Start date Start date
A

Adam

Guest
I have three loops on category.php the first is pulling the most recent single post and the second two loops are filtering the posts into odd and even order to display in columns.

All is working perfectly apart from that the first post in duplicated in the second loop.

I have tried every method I know to stop duplicated posts but I'm stuck on this one.

Loop one:

Code:
        <?php $args = array( 'posts_per_page' => 1, 'paged' => 1, ); global $wp_query; $duplicate = 0; $the_query = new WP_Query( array_merge( $wp_query->query, $args )  ); while ( $the_query->have_posts() ) : $the_query->the_post(); ?>

    <?php endwhile; ?>

Loop Two:

Code:
        <?php if (have_posts()) : while(have_posts()) : $i++; if(($i % 2) !== 0) : $duplicate = 0; $wp_query->next_post(); else : the_post(); if( $post->ID == $do_not_duplicate ) continue; ?>

    <?php endif; endwhile; else: ?>
    <?php endif; ?>

Loop Three:

Code:
        <?php $i = 0; rewind_posts(); ?>
    <?php if (have_posts()) : while(have_posts()) : $i++; if(($i % 2) == 0) : $duplicate = 0; $wp_query->next_post(); else : the_post(); if( $post->ID == $do_not_duplicate ) continue; ?>

    <?php endif; endwhile; else: ?>
    <?php endif; ?>
<p>I have three loops on category.php the first is pulling the most recent single post and the second two loops are filtering the posts into odd and even order to display in columns.</p>

<p>All is working perfectly apart from that the first post in duplicated in the second loop. </p>

<p>I have tried every method I know to stop duplicated posts but I'm stuck on this one. </p>

<p>Loop one: </p>

<pre><code> <?php $args = array( 'posts_per_page' => 1, 'paged' => 1, ); global $wp_query; $duplicate = 0; $the_query = new WP_Query( array_merge( $wp_query->query, $args ) ); while ( $the_query->have_posts() ) : $the_query->the_post(); ?>

<?php endwhile; ?>
</code></pre>

<p>Loop Two: </p>

<pre><code> <?php if (have_posts()) : while(have_posts()) : $i++; if(($i % 2) !== 0) : $duplicate = 0; $wp_query->next_post(); else : the_post(); if( $post->ID == $do_not_duplicate ) continue; ?>

<?php endif; endwhile; else: ?>
<?php endif; ?>
</code></pre>

<p>Loop Three:</p>

<pre><code> <?php $i = 0; rewind_posts(); ?>
<?php if (have_posts()) : while(have_posts()) : $i++; if(($i % 2) == 0) : $duplicate = 0; $wp_query->next_post(); else : the_post(); if( $post->ID == $do_not_duplicate ) continue; ?>

<?php endif; endwhile; else: ?>
<?php endif; ?>
</code></pre>
Continue reading...
 

Latest posts

Top