Menu

Fix broken pagination on WordPress custom post types

So, you’ve created a custom post type for your WordPress site but when testing your archive, pagination isn’t working and instead shows your 404 page. Here’s a potential fix that worked for me on a recent project.

First, let’s double-check that we’ve set up our archive page to display your custom post type archive.

Open your archive-mycpt.php template file. Just before the default loop, let’s verify you’ve set up your post type paging correctly:


<?php 
 $paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
    query_posts(array(
    'post_type' => 'mycpt', // your CPT name
    'paged' => $paged,
    'orderby'=>'date',
    'posts_per_page' => 10 // set this to desired #
 ));
?>

// the loop...


So, you’ve double-checked and it all checks out but you’re still getting the 404 error and even resetting permalinks doesn’t do the trick.

Try this…

In your WordPress dashboard, go to Settings > Reading.

WordPress reading settings display number of posts field

Under Blog pages to who at most, you likely have 10, 12, or some other number and you find that the number is different than the one set in the PHP we just looked at in your archive template. That’s where the conflict may be.

Change the value to 1 and save changes.

Now try it out!

Archived under:
Share:
This site uses cookies to collect basic info to help improve your experience. Read my Privacy Policy Accept