I have my own custom post type, and 15 items there.
This code shows all the items:
<?php $loop = new WP_Query( array( 'post_type' => 'my_post_type', 'posts_per_page' => 15 ) );
while ( $loop->have_posts() ) : $loop->the_post(); ?>
(...)
When I change posts_per_page to “5” there should be 3 pages, but it displays only 5 items and there are no other pages (or at least I don’t know how to access them).
This code displays nothing:
<?php if ( $wp_query->max_num_pages > 1 ) : ?>
{menu or any html code}
<?php endif; ?>
Maybe I do something wrong? I have the whole code/loop in page-myposttype.php file.
I’ve tried this code:
$temp = $wp_query;
$loop= null;
$paged = get_query_var('paged') ? get_query_var('paged') : 1;
$loop = new WP_Query( array(
'post_type' => 'my_post_type',
'paged' => $paged,
'posts_per_page' => 2 ) );
while ( $loop->have_posts() ) : $loop->the_post(); ?>
But no luck… When I type wordpress/my_post_type/page/2 (page/3 etc.) manually I see other pages and they work & look fine. But I’m unable to echo the default navi… 🙁
Answered a question that’s virtually identical to this very recently on the WordPress.org forums.
Custom Post Type Archive Page – Pagination Isn’t Working
I’ve provided a work-around / fix in that thread that should also work for you to.
🙂
EDIT: You also need to add the paging parameter to your query..
Eg.
I reformatted the code to make it a little more readable, end result will be the same.