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

I'm trying desperately to get the pagination on my custom post type archive page to work, but I keep getting a 404 error whenever I click on <?php next_posts_link('&laquo; Older Entries') ?> for p2 of results.

Here's my situation:

  • I've created a file called 'archive-bvdirectory.php' for my custom post type 'bvdirectory' (see how I've set it up in my functions.php below) and 'single-bvdirectory.php' for viewing single custom posts, both of which I can view fine.
  • I have deleted a page called 'directory' I created permanently as I read this can cause problems with WP's rewrite rules (the URL would be the same, so that makes sense)
  • I have refreshed my permalinks ad infinitum and it changes nothing.

Can anyone see a problem with my code or suggest something for me to try?

Thanks for your time,


CTP and taxonomies are set up like this:

function osu_bv_company() {

    // Create Directory custom post type
            'label'                 => __( 'Directory' ),
            'public'                => true,
            'has_archive'           => 'directory',
            'show_ui'               => true,
            'query_var'             => true,
            'supports'              => array(
                // 'trackbacks',
                // 'comments'
            'rewrite' => array('slug'=>'directory')

    // Create Industry taxonomy
    $bvindustrylabels = array(
        'name'                      => 'Industry',
        'singular_name'             => 'Industry',
        'search_items'              => 'Search industries',
        'all_items'                 => 'All industries',
        'parent_item'               => 'Parent industry',
        'edit_item'                 => 'Edit industry',
        'update_item'               => 'Update industry',
        'add_new_item'              => 'Add new industry',
        'new_item_name'             => 'New industry name',
        'choose_from_most_used'     => 'Choose from most used industries'
            'hierarchical' => true,
            'labels' => $bvindustrylabels,
            'sort' => true,
            'args' => array('orderby' => 'term_order'),
            'rewrite' => array('slug' => 'industry')
    // Create Company Size taxonomy
    $bvcosizelabels = array(
        'name'                      => 'Company size',
        'singular_name'             => 'Company size',
        'search_items'              => 'Search company sizes',
        'all_items'                 => 'All company sizes',
        'parent_item'               => 'Parent company size',
        'edit_item'                 => 'Edit company size',
        'update_item'               => 'Update company size',
        'add_new_item'              => 'Add new company size',
        'new_item_name'             => 'New company name',
        'choose_from_most_used'     => 'Choose from most used company sizes'
            'hierarchical' => true,
            'labels' => $bvcosizelabels,
            'sort' => true,
            'args' => array('orderby' => 'term_order'),
            'rewrite' => array('slug' => 'size')
add_action('init', 'osu_bv_company');

I have the following arguments set for my loop in archive-bvdirectory.php

$paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
$args = array(
    // General args
    'post_type'             =>  'bvdirectory',
    'posts_per_page'        =>  2,
    'orderby'               =>  'title', // set this in form
    'order'                 =>  'ASC', // Set this in form
    'paged'                 =>  $paged  

// Filter posts
share|improve this question
Ok, some additional details - I re-added the 'directory' page and am using a template for that instead of 'archive-bvdirectory.php' for controlling the look of the Custom Posts as the slug for my custom posts is 'bvdirectory', so I think there must be no conflict there. Using this new 'directory' page, I can get pagination to work ONLY when I select the same number of posts_per_page in the admin end i.e. I select 2 for 'Blog pages show at most'. I guess this is a workaround for the moment, but I think I need to find a proper solution rather than this... – Osu Aug 3 '12 at 17:12

Your error is likely get_query_var('paged') should be get_query_var('page').


You should avoid calling query_posts in the template, it is a waste of resources, as you're just discarding the original query which has already happened.

Hook pre_get_posts to instead alter the query before it happens:

function wpa60728_pre_get_posts( $query ) {
    if ( 'bvdirectory' == get_post_type() && is_main_query() )
        $query->set( 'posts_per_page', 2 );

add_action( 'pre_get_posts', 'wpa60728_pre_get_posts' );
share|improve this answer
Hi Milo - how do I set the parameters in my loop then if I don't use query_posts? i.e. setting the limit of posts to show, ordering etc? My ultimate aim with this is to allow users to filter posts on this page by submitting a form with with my custom taxonomies. Oh, and I changed the 'paged' to 'page', but it doesn't seem to have sorted it... thanks for your help so far – Osu Aug 4 '12 at 19:24

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.