2
votes

I'm creating a custom template called archive-key_piece.php to accommodate the Custom Post Type, 'Key Pieces'. I would like to change the posts_per_page from 10 posts to 12. I have done so using query_posts('post_type=key_piece&posts_per_page=12&paged='.$paged);

The issue is that when I use query_posts(), it disables the pagination completely (even /key-piece/page/2/ won't work, it will just turn the same results as page 1).

When I use

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

this allows me to access the next pages manually by url (key-piece/page/2/ etc.) but it still disables the next_posts_link()

I have also tried this in functions.php

function number_of_posts_on_archive($query){
    if ($query->is_archive) {
            $paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
            $query->set('posts_per_page', 12);
            $query->set('pagination', $paged);
   }
    return $query;
}

add_filter('pre_get_posts', 'number_of_posts_on_archive');

but with the same results.

Any help is greatly appreciated. Thank you!

1
Please, don't use query_posts for post query in WordPress. This is highly discouraged. - dingo_d

1 Answers

2
votes

Here you go.

<?php
  $variable = $WPQuery; 
  $WPQuery = null; 
  $WPQuery = new WPQuery(); 
  $WPQuery->query('showposts=6&post_type=news'.'&paged='.$paged); 

  while ($WPQuery->have_posts()) : $WPQuery->the_post(); 
?>

  <!-- Template Stuff Here-->

<?php endwhile; ?>

<div class="navigation">
    <?php previous_posts_link('&laquo; Newer Here') ?>
    <?php next_posts_link('Older Here &raquo;') ?>
</div>

<?php 
  $WPQuery = null; 
  $WPQuery = $variable;  // Reset
?>

Hope it will help you.