Jump to content

Pagination Problem When Using Two Queries in Wordpress


slaterino

Recommended Posts

Hi,
I'm having a real problem with one of my Wordpress category pages. I use a 3-column grid system on this page and just recently I needed to add an advert to the page, so I thought I would do one query at the top with the first two posts, then add the advert to complete the row. Then I would use a second query underneath creating the posts using the traditional grid system with 3 in each row. 
 
This is working well except for the pagination, which adds the two items form the first query everytime it paginates. You can see this in action at http://soundsandcolours.com/music/
 
Does anyone know what I can do to make the Pagination ignore the first query, and just keep running the second query instead. I've included all of my code below:
 
1st Query:
$query_string;
$musiccat_posts = new WP_Query($query_string."&posts_per_page=2");
if ($musiccat_posts->have_posts()):
$musiccatIDs = array();
while($musiccat_posts->have_posts()):$musiccat_posts->the_post();
$musiccatIDs[] = get_the_ID();

2nd Query:

$paged = ( get_query_var( 'paged' ) ) ? absint( get_query_var( 'paged' ) ) : 1;
global $moremusiccat_query;
        $music_args = array(
            'cat' => 1841,
            'posts_per_page' => 15,
            'post__not_in' => $musiccatIDs,
            'paged' => $paged
        );      
$moremusiccat_query = new WP_Query( $music_args );
while ($moremusiccat_query -> have_posts()) : $moremusiccat_query -> the_post(); ?>
Pagination Code:
                    $big = 999999999; // need an unlikely integer
                    echo paginate_links( array(
                        'base' => str_replace( $big, '%#%', esc_url( get_pagenum_link( $big ) ) ),
                        'format' => '?paged=%#%',
                        'current' => max( 1, get_query_var('paged') ),
                        'total' => $moremusiccat_query->max_num_pages
                    ) );
Any help would be massively appreciated!
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.