Well I’m here again with almost the same problem as I had in this post three weeks ago, but let me explain what has happened since then:
I was originally using one loop to display the most recent sticky post at the top of the front page, then a second loop to display every other post (except for all other stickies). Here’s my code as it stands now:
// first loop to display only my single, MOST RECENT sticky post
$sticky = get_option('sticky_posts');
$wp_query = new WP_Query(array('post__in' => $sticky, 'caller_get_posts' => 1, 'orderby' => ID, 'showposts' => 1)); ?>
<?php while (have_posts()) : the_post(); ?>
<!-- loop code -->
<?php endwhile; wp_reset_query(); ?>
// second loop to display every other post, excluding sticky posts
<?php query_posts(array('post__not_in' => get_option('sticky_posts'))); // exclude all sticky posts ?>
<?php if (have_posts()) : while (have_posts()) : the_post(); ?>
<!-- loop code -->
<?php endif; wp_reset_query(); ?>
What is happening here is perfect…for the front page only. I get my nice single/most-recent sticky post at the very top, followed by another 5 posts. Unfortunately, if I page over to the 2nd, 3rd, 4th, etc pages – all I see are the same 5 posts that were under the sticky post on the front page!
I’m quite new with the concept of multiple loops, so I could really use a hand here!
Thank you in advance 🙂
I see a few issues that are probably contributing to your issue:
query_posts()
to modify the primary Loop.caller_get_posts
parameter has been deprecated, in favor ofignore_sticky_posts
$wp_query
variable is a defined global. Using it outside of its intended use may cause unintended circumstances.So, first, you need to determine which is your primary Loop. I will assume this to be the second loop.
Second, come up with a unique, descriptive name for your secondary loop (i.e. your first loop), such as
$most_recent_sticky_post
.That should leave you with:
Now, since you’re no longer stomping on
$wp_query
, your pagination should work properly.Edit
Okay, other things:
showposts
parameter is also deprecated. Usepost_per_page
instead.e.g.:
I don’t know that this will make a difference, but I prefer to modify the default query using this method.
query_posts()
to remember that it’s supposed to use paging. Add'paged' => get_query_var('paged')
to your$custom_query_args
array:e.g.
Where does that get us?
Shouldn’t you be using paging parameters in your WP_Query
It could be get_query_var( ‘paged’ ) depending on WP version I believe.
WP_Query pagination parameters here