Ask your WordPress questions! Pay money and get answers fast! Comodo Trusted Site Seal
Official PayPal Seal

Fix homepage and page 2 loop so it doesn't skip posts WordPress

I have an index.php with 2 loops - one runs through on the homepage, the second runs through on all other pages, so when you click 'view more' it displays the next series of posts.

The issue is that several posts are missing:

Between frontpage and page 2: 4 posts
Between page 2 and page 3: 3 posts
Page 3 and Page 4: 3 posts

Here's the code:

Answers (2)


Kristin Falkner answers:

Couple things to look at:

With $do_not_duplicate how you have it set up on your second loop, it will still count any skipped posts from prior loops as one towards any showposts query value, I believe. Meaning, for example, if your showposts equals 8 and the loop queries 8 posts, but skips 2 posts because they'd be duplicates, your second loop would display only 6 posts. Does this make sense? So if you want to show 8 posts in your second loop and use $do_not_duplicate, in your second query you need to include 'post__not_in'=>$do_not_duplicate

With multiple custom loops like you have, you might also try putting <?php wp_reset_query(); ?> at the end of your loops, as well. More info on wp_reset_query from the Codex: [[LINK href=""]][[/LINK]]


Fahad Murtaza answers:

I am seconding Kristin Falkner here

<?php wp_reset_query(); ?>

has always worked for me.