0

I've got a query that looks like this:

$args = array (
    'post_type'              => $postType,
    'paged'                  => $paged,
    'pagination'             => true,
    'posts_per_page'         => '10',
    'order'                  => 'DESC',
    'orderby'                => 'date',
);

// The Query
$wp_query = new WP_Query( $args );

// The Loop
if ( $wp_query->have_posts() ) {
    while ( $wp_query->have_posts() ) {
        $wp_query->the_post();

            // post stuff

    }
} else { 
    // no posts 
}

pagination($additional_loop->max_num_pages); wp_reset_postdata(); wp_reset_query();

I've also got some custom pagination that in functions.php that looks like this:

function pagination($pages = '', $range = 4)
{  
     $showitems = ($range * 2)+1;  

     global $paged;
     if(empty($paged)) $paged = 1;

     if($pages == '')
     {
         global $wp_query;
         $pages = $wp_query->max_num_pages;
         if(!$pages)
         {
             $pages = 1;
         }
     }   

     if(1 != $pages)
     {
         echo "<div class=\"pagination\"><span>Page ".$paged." of ".$pages."</span>";
         if($paged > 2 && $paged > $range+1 && $showitems < $pages) echo "<a href='".get_pagenum_link(1)."'>&laquo; First</a>";
         if($paged > 1 && $showitems < $pages) echo "<a href='".get_pagenum_link($paged - 1)."'>&lsaquo; Previous</a>";

         for ($i=1; $i <= $pages; $i++)
         {
             if (1 != $pages &&( !($i >= $paged+$range+1 || $i <= $paged-$range-1) || $pages <= $showitems ))
             {
                 echo ($paged == $i)? "<span class=\"current\">".$i."</span>":"<a href='".get_pagenum_link($i)."' class=\"inactive\">".$i."</a>";
             }
         }

         if ($paged < $pages && $showitems < $pages) echo "<a href=\"".get_pagenum_link($paged + 1)."\">Next &rsaquo;</a>";  
         if ($paged < $pages-1 &&  $paged+$range-1 < $pages && $showitems < $pages) echo "<a href='".get_pagenum_link($pages)."'>Last &raquo;</a>";
         echo "</div>\n";
     }
}

Again, works great. The only thing I can't figure out is how to limit the actual number of pages that are returned. For example, I might have 300 posts, paged into pages of 10. However, I only want to show a total of 30 posts split into 3 pages of 10.

-1

Change your query code to this:

add_filter( 'post_limits', 'my_post_limits' );

// The Query
$wp_query = new WP_Query( $args );

remove_filter( 'post_limits', 'my_post_limits' );

In your theme/functions.php, add this:

function my_post_limits( $limit, $query ) {

    return 'LIMIT 0, 30';

}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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