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 a custom post type, jobs, being displayed on an external page using WP_Query() - the query itself is working fine.

However when I try to paginate the results, the older/newer links show up, but when I click on them, the content doesn't change - ie the page 'number' changes in the URL & the page reloads, but the posts don't move on.

I've tried using Wordpress' default next_posts_link & previous_posts_link and also with the wp_pagenavi plugin. In the code below I'm using wp_pagenavi .

Here's my code:

<?php $paged = (get_query_var('paged')) ? get_query_var('paged') : 1;

        $params = 
        array(  'post_type'          => 'job', 
            'post_status'        => 'publish',
            'posts_per_page'     => 3,
             'paged'=>$paged
        );

        $temp = $wp_query;
        $wp_query= null;
        $wp_query = new WP_Query();


        $wp_query->query($params); ?>

  <?php if (function_exists('wp_pagenavi')){ wp_pagenavi(); } ?>

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

// doing things with the post

 <?php endwhile; endif ?>
 <?php $wp_query = null; $wp_query = $temp; wp_reset_query() ?>

Any help would be greatly appreciated it - this is driving me up the wall! ^_^

share|improve this question
    
How many posts do you have in total? –  Rob Vermeer Jan 9 '12 at 22:27
    
10 - I wish it was that simple ^_^ –  user11860 Jan 9 '12 at 22:28

1 Answer 1

A problem with a custom query is that the posts_per_page resets before the page loads. So if you got 10 posts, than you only have one page, because the default posts_per_page is 10. If you have 11 posts than you will see the second page, but not beyond that.

Solution for this is changing your posts_per_page settings in the back-end: Settings > Reading > Blog pages show at most > 3. But this will change all archive page settings. Quick fix for this is adding

<?php global $query_string; query_posts($query_string . '&posts_per_page=10'); ?>

at the top of your archive templates where you want the default posts_per_page.

share|improve this answer

Your Answer

 
discard

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