Why does “Blog pages show at most” interfere with my custom wp_query?

I’m very new to WordPress, especially when it comes to creating a custom loop as per below. This works fine, however I’m perplexed why “Blog pages show at most” (under Settings > Reading) is interfering with the query.

In the example below, I have post_per_page set at 10. If I leave the default “Blog pages show at most” setting as 10 posts it works fine because they both match and calculates the pages correctly. However if I change the “posts_per_page” to 5, I get a few extra pages added to the pagination, which display “page not found” when clicked.

Is it possible to override this setting from the admin? I thought creating a custom wp_query would override this anyway. What am I doing wrong?

I’m also using wp_pagenavi for the pagination as you can see in the example below, and have a custom post type of “listing”. I’m using WordPress 3.1.3.

<?php $custom_query = new WP_Query( array( 'post_type' => 'listing', 'posts_per_page' => 10, 'paged' => get_query_var('paged') ) ); ?>  

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

    <div id="post-<?php the_ID(); ?>">   
        // stuff here
    </div>

<?php endwhile; endif; ?>

//wp_pagenavi 
<?php 
    if (function_exists('wp_pagenavi')) {
    wp_pagenavi( array( 'query' => $custom_query ) ); } 
?>

<?php wp_reset_postdata(); ?>

4 Answers
4

see: http://scribu.net/wordpress/wp-pagenavi/wpn-2-74.html

Leave a Comment