WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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?


share|improve this question
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 Jun 1 '11 at 9:08

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');
share|improve this answer
up vote 2 down vote accepted

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?

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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