im using paginate_links function to create pagination on my custom post type archives, no matter what i do im hitting 404 errors when going to view page 2 (ie clicking to go on one page in the pagination trail).

I've checked and researched and dont seem to be getting anywhere with it all. heres my before the loop query inside archive-MY_CUSTOM_POST_TYPE.php:


global $wp_query;

$args = array_merge( $wp_query->query, array( 'post_type' => 'sales', 'posts_per_page'  => 1, ) );

query_posts( $args );

if (have_posts()) :
while (have_posts()) : the_post();  

and lower down after the loops endif and above wp_reset_query i have

<?php endif; ?>

<div class="clear"></div><!-- / clear -->

<div class="pagination">

global $wp_query, $wp_rewrite;
$wp_query->query_vars['paged'] > 1 ? $current = $wp_query->query_vars['paged'] :    $current = 1;

$pagination = array(
'base' => @add_query_arg('page','%#%'),
'format' => '',
'total' => $wp_query->max_num_pages,
'current' => $current,
'show_all' => true,
'type' => 'plain'

if( $wp_rewrite->using_permalinks() )
$pagination['base'] = user_trailingslashit( trailingslashit( remove_query_arg( 's', get_pagenum_link( 1 ) ) ) . 'page/%#%/', 'paged' );

if( !empty($wp_query->query_vars['s']) )
$pagination['add_args'] = array( 's' => get_query_var( 's' ) );

echo paginate_links( $pagination );

</div><!-- / paginate -->  

On my loop-index.php this works with no problem, but on a loop inside Custom Post Type its a no go, i have no clashes with duplicated slugs as i have read that this can be an issue, so im taking it that it is something to do with how im querying the posts before the loop, any pointers?


  • Well i made some progress, although its far from ideal it works. What i had to do was go into wp-admin >> reading and set posts per page equal to what i am having on my custom post type pages, doing this pagination works but as i say its far from ideal as i want 5 posts per page custom post types and index and 10 posts per page for blog...
    – MartinJJ
    Commented Jun 1, 2011 at 9:08

3 Answers 3


Martin's fix works, but a better solution is to use the pre_get_posts function.


function custom_type_archive_display($query) {
    if (is_post_type_archive('custom_type')) {

add_action('pre_get_posts', 'custom_type_archive_display');

If anyone else as the same issue my full workaround is:
1) in wp-admin >> settings >> reading set blog posts to show as 1.
2) then override this in loop-blog.php to posts_per_page => 10.
3) in your custom post type loop.php files set posts_per_page => 5.

Remember these are the settings that i require, your needs may be different, bottom line is, set blog posts in wp-admin to 1, you can configure the other number of posts_per_page to your own needs

now all is working good, a little hacky but at least it works, so my next question is >>> is this a wp bug?


I know this is old but I've had the same problem and solved it by changing the permalink of the page that was causing the 404.

This is because, apparently, you cannot have a page-slug with the same name as your custom post type.

All credit goes to Ryan S. for sharing the original solution: http://www.sutanaryan.com/2013/09/404-error-in-custom-post-type-pagination-wordpress/

  • The added link to the article goes to a 404 page as well ironically.
    – rhand
    Commented Dec 20, 2021 at 0:43

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.