hi im trying to output pagination without any success. below is my code in a page-products.php template

<?php $products_query = new WP_Query(array(
    'post_type' => 'product',
    'posts_per_page' => 4,
    'paged' => (get_query_var('page') ? get_query_var('page') : 1),

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

<?php the_content; ?>

<?php endwhile; ?>
<?php posts_nav_link();?>
<?php endif; ?>

i cant seem to output my pagination links. can anybody help spot whats wrong?

  • is posts_nav_link() only for paginating the default 'post' post type?. i tried using echo paginate_links() with no success also. Oct 3, 2012 at 18:15

1 Answer 1


I believe the query var that you are retrieving should be paged and not page. See the codex and adjust your query to the following:

$products_query = new WP_Query(array(
    'post_type' => 'product',
    'posts_per_page' => 4,
    'paged' => (get_query_var('paged') ? get_query_var('paged') : 1),

However, if this is an archive for your product post type why not use archive-product.php and let WP handle the query and pagination automatically? See template hierarchy.

  • actually ive been wanting to do that, how do i access the page without giving it a page template name and making a page and then selecting it as a template? i prefer my templates to be called without assigning it manually. i also tried that code on a taxonomy-collection.php template, would that be the same thing? Oct 3, 2012 at 18:44
  • That is a totally different question, but basically you'd tell your custom post type to have an archive: codex.wordpress.org/Function_Reference/… and you can change the URL via the rewrite parameter Oct 3, 2012 at 20:20

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