0

I'm looking to query multiple post types and paginate them so the results are across multiple pages. The markup I have is as follows:

<?php query_posts( array(
     'posts_per_page' => 100,
     'post_type' => array( 'regularproducts', 'wpsc-product' ),
     'paged' => ( get_query_var('page') ? get_query_var('page') : 1 ),
));
?>

<?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>

    <div class="post_type">
    <?php if ( 'regularproducts' == get_post_type()  ) : ?>FEATURE<?php endif; ?>
    <?php if ( 'wpsc-product' == get_post_type()  ) : ?>REPORT<?php endif; ?>
    </div>

    <a href="<?php the_permalink(); ?> "><?php the_title(); ?></a>

    <div class="excerpt">
    <?php echo get_the_excerpt(); ?>
    </div>

<?php endwhile; endif; ?>

<nav id="page_nav">
    <?php posts_nav_link(' ',' ','load more posts +'); ?>
</nav>

<?php wp_reset_query(); ?>

The query works as far as showing both post types, but they're not paginating. i.e. on /page/2/ it's displaying the same 100 results as page 1, is there a reason for this / solution? Any suggestions would be greatly appreciated!

  • On which page/template are you doing this. Also, never use query_posts – Pieter Goosen Nov 6 '14 at 13:09
  • @PieterGoosen It's being used on page-products.php template. OK, so is there a way of achieving what I'm after? – user1374796 Nov 6 '14 at 13:47
  • And is this a front page, because if not, page must be changed to paged – Pieter Goosen Nov 6 '14 at 14:12
  • @PieterGoosen ah yes, changing to paged worked a treat! Although for some reason the wpsc-product post type aren't being paginated as none of those posts are appearing on page 2 onwards? – user1374796 Nov 6 '14 at 23:49
  • I don't see any reason for this happening from the code given. It is possible that there are no posts to show from that cpt within a specific page or a filter somewhere in your theme that is causing this. – Pieter Goosen Nov 7 '14 at 4:12

Your Answer

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

Browse other questions tagged or ask your own question.