I know there about a thousand pagination issue questions on here, and I've looked at them, but I can't seem to figure out what's going wrong with mine. This is a loop on a custom post type archive template, but it should call ALL POSTS since I'm using it as a blog. At the very top of the template, is a query for a specific page, but I don't think that's what's causing the problem.

What happens is that on the second page I get a 404 error.

<?php get_header(); ?>
<?php // query post #4606
$post_id = 4606;
$queried_post = get_post($post_id);
$title = $queried_post->post_title;?>
<?php echo $title;?>
<!-- The Actual Loop, with a count so that I can style the first post differently   -->
<?php $post = $posts[0]; $c=0;
$args = array(
    'post_type'=> 'post',
    'posts_per_page' => 7,
    'paged' => ( get_query_var('paged') ? get_query_var('paged') : 1),
while (have_posts()) : the_post();
<!--Featured Post-->
<?php $c++;
if( !$paged && $c == 1) :?>
                <?php if ( has_post_thumbnail()) : ?>
                    <a href="<?php the_permalink(); ?>" title="<?php the_title_attribute(); ?>" >
                        <?php the_post_thumbnail('archive-featured-img', array('class' => 'aligncenter')); ?>
                <?php endif; ?>
                <!--the title and content etc.-->
<!--Other Posts-->
<?php else :?>           
                 <!--the title and content for all other posts-->         
<?php endif;?>
<?php endwhile; ?>
<!-- The end of the loop   -->
<!--Page Navigation-->
<?php if (  $wp_query->max_num_pages > 1 ) : ?>
                <div id="post-nav" class="cf">
<div class="nav-previous"><?php next_posts_link('Next Page &#187;', 0); ?></div>
<div class="nav-next"><?php previous_posts_link('&#171; Previous Page', 0); ?></div>
<?php endif; ?>
wp_reset_query();  // Restore global post data

        <!--SIDEBAR--repeats the page title from above, then dynamic sidebar-->      
                <h1><?php echo $title;?></h1>
                <?php echo $queried_post->post_content;?>

            <?php dynamic_sidebar( 'Main Blog Page Sidebar' ); ?>

<?php get_footer() ?>
  • it's a custom post type archive, but you're loading posts of the type post? get rid of the call to query_posts, and use the pre_get_posts action. many questions on here with answers explaining why you should never use query_posts.
    – Milo
    Jul 10 '13 at 14:50
  • Right. I'm using the custom post type for a couple of reasons, but the main one is so I can show all posts on the /blog/ url. The homepage is reserved for static content. Maybe there is a better solution?
    – Josh M
    Jul 10 '13 at 15:24
  • possible duplicate of How to fix pagination for custom loops? Oct 31 '13 at 14:36

@Milo Thanks, the pre_get-posts seems to work perfectly. I was missing that before, thought my choices were between wp_query and query_posts.

The below should ONLY alter the query on the "rg_blog" custom post type archive, right?

function blog_filter($query) {
  if ( !is_admin() && $query->is_main_query() ) {
    if ($query->is_post_type_archive('rg_blog')) {
      $query->set('post_type', 'post');
  • This worked perfectly EXCEPT now the two queries for '$post_id = 4606' don't work. Maybe the pre_get_posts function is canceling that out?
    – Josh M
    Jul 10 '13 at 16:13

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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