• 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 https://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!

  • The topic ‘Pagination Problem When Using Two Queries’ is closed to new replies.