Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

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... :(

share|improve this question
    
where is your code to print out the next/previus page link? –  Bainternet Feb 2 '11 at 0:39
    
Your query uses $loop, but you check the number of pages of $wp_query. $wp_query will contain the default query, which is probably a page in your case? –  Jan Fabry Feb 2 '11 at 8:54
add comment

1 Answer

up vote 1 down vote accepted

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.

$args = array( 
    'post_type' => 'my_post_type', 
    'paged' => get_query_var('paged') ? get_query_var('paged') : 1,
    'posts_per_page' => 15, 
);
$loop = new WP_Query;
$loop->query( $args );

I reformatted the code to make it a little more readable, end result will be the same.

share|improve this answer
    
I'm using wp_pagenavi and it doesn't help me at all :( Eeven with your code when I click Next/Prev Entry - I'm getting the same items all over again (for example if there are 6 items and I display 2, I'm getting 3 pages of items number 1 and 2). –  Wordpressor Feb 2 '11 at 13:50
    
That's because you're missing the paging parameter in your query, i'll add it into my answer. –  t31os Feb 2 '11 at 13:53
    
your answer was very helpful and works fine but I BADLY need to display the default Wordpress pagination/page navigation. Do you have any ideas how to achieve that? I'm using wp_pagenavi plugin based on the default WP navigation and it doesn't "work" with your code. –  Wordpressor Feb 3 '11 at 18:40
    
nvm, figured it out (had to put pagenavi code instead of default links), thanks a lot! –  Wordpressor Feb 3 '11 at 18:52
    
Glad you got it figured out and i'm happy to have helped... :) –  t31os Feb 3 '11 at 18:54
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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