Support » Fixing WordPress » Stuck on custom post type archives with pagination

  • Hi all,

    I’ve tried many different ways to get pagination working on my custom post archives to no avail. Can anyone help please? Here’s where I’m at:

    Post type is called ‘Projects’ and has the slug amended to videos:

    function projects_post_type() {
        register_post_type('projects', array(
            'labels' => array(
                'name' => 'Projects',
    		'has_archive' => true,
    		'rewrite' => array(
        		'slug' => 'videos'

    I have created a specific archive-projects.pho with the following loop:

    <?php  query_posts( 'post_type=projects&showposts=8&paged='.$paged );
      if (have_posts()) : while (have_posts()) : the_post(); ?>
    post code etc.
             <?php endwhile; ?>
                      <div id="nav-below" class="navigation">
                        <div class="nav-previous"><?php next_posts_link( __( '<span class="meta-nav">&larr;</span> Older posts', 'vimeodrome' ) ); ?></div>
                        <div class="nav-next"><?php previous_posts_link( __( 'Newer posts <span class="meta-nav">&rarr;</span>', 'vimeodrome' ) ); ?></div>
                      </div><!-- #nav-below -->
      <?php endif; ?>

    The first page of the archive displays ok but when I click ‘older posts’ I get a 404 error on …/videos/page/2

    I’ve treid resetting my permalinks (which are currently set top custom > /%postname%/) but it still won’t work. All tutorials I’ve found state the code I’ve used above should work, so what am I doing wrong?

Viewing 3 replies - 1 through 3 (of 3 total)
  • Moderator keesiemeijer



    Try to set the $paged variable:

    $paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
    query_posts( 'post_type=projects&posts_per_page=8&paged='.$paged );

    Thanks Keesiemeijer but it still doesn’t work with that code.

    I have managed to get it to work in a slightly different way though, which is to alter ‘has_archive’ to be ‘false’, then to add a template name to the archive-projects.php and finally create a standard page called Videos and set it to use the archive-project template. This allows me to add the link to the dashboard set menus as well which is a bonus.

    However, ideally I rather not have to rely on the user creating a page for the archive and that the custom post archives just worked ‘out of the box’.

    Forgot to add that in the example above where I created a Videos page for the ‘projects’ to appear, that I had to delete the

    'rewrite' => array(
        		'slug' => 'videos'

    part of the functions code.

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Stuck on custom post type archives with pagination’ is closed to new replies.