Pagination Not Working on `WP_Query` Archive Page

Question

I have an archive page that pulls two different custom post types into an archive using WP_Query(). Because there is a home page to the site which shows 9 of the custom post type posts, I offset the archive page by 9 posts.

The code for this is:

$homePageArticles = new WP_Query(array(
        'posts_per_page' => 18,
        'offset' => 9,
        'post_type'=> array('articles', 'featured')
    ));

    while(  $homePageArticles->have_posts()){
            $homePageArticles->the_post(); ?>

            // HTML

<?php } ?>

However on this archive page the <?php echo paginate_links();?> function to show the pagination pages doesn’t work.

I can click through the numbers or use the next and previous arrows, but it just shows the same posts on each page.

The pagination code I’m using is:

<p>
    <?php echo paginate_links(array(
        'prev_text' => 'NEWER',
        'next_text' => 'OLDER',
        'mid_size' => 0
    ));?>
</p>

On normal custom archive pages on the site (which don’t use WP_Query();) the pagination works fine.

Any help or assistance would be amazing.

0
, , The Chewy 4 years 2020-03-30T00:51:20-05:00 0 Answers 74 views 0

Leave an answer

Browse
Browse