Title: problem with  max_num_pages
Last modified: August 22, 2016

---

# problem with max_num_pages

 *  [synthi100](https://wordpress.org/support/users/synthi100/)
 * (@synthi100)
 * [11 years, 6 months ago](https://wordpress.org/support/topic/problem-with-max_num_pages/)
 * Hi,
    I’m new to WordPress. I’am having problems with a pagination I made. Everything
   works fine if I show all the posts with this query:
 *     ```
       $args = array('posts_per_page' => 7, 'paged' => $current_page, 'post_type' => 'post', 'suppress_filters' => false);
       $postslist = get_posts( $args );
       global $wp_query;
       $totalpages = $wp_query->max_num_pages;
       ```
   
 * In this case, the value of $totalpages = 94 which is correct.
 * However, the visitors should also be able to select that they only want to see
   the posts which belong to a certain category. In that case, I add category to
   the arguments array like this:
    `$args = array('posts_per_page' => 7, 'paged'
   => $current_page,'category' => $category_id, 'post_type' => 'post', 'suppress_filters'
   => false);` The posts of the correct category are shown correct on my page, however`
   global $wp_query; $totalpages = $wp_query->max_num_pages; stills gives me the
   result 94 pages, which is not correct because 94 pages is the correct amount 
   of pages for all categories. Can someone explain me how I can find the total 
   number of pages when I query the posts of 1 category?
 * Thanks in advance

Viewing 4 replies - 1 through 4 (of 4 total)

 *  [Michael](https://wordpress.org/support/users/alchymyth/)
 * (@alchymyth)
 * [11 years, 6 months ago](https://wordpress.org/support/topic/problem-with-max_num_pages/#post-5448923)
 * try and work with `WP_Query()` instead of `get_posts()`;
 * example:
 *     ```
       $args = array('posts_per_page' => 7, 'paged' => $current_page,'category' => $category_id, 'post_type' => 'post', 'suppress_filters' => false);
       $postslist = new WP_Query( $args );
       $totalpages = $postslist->max_num_pages;
       ```
   
 * you will also need to adjust the way you output the posts.
 * review [http://codex.wordpress.org/Class_Reference/WP_Query](http://codex.wordpress.org/Class_Reference/WP_Query)
 *  Thread Starter [synthi100](https://wordpress.org/support/users/synthi100/)
 * (@synthi100)
 * [11 years, 6 months ago](https://wordpress.org/support/topic/problem-with-max_num_pages/#post-5448927)
 * Thanks for you reply.
    I tested it like this but the result is still 94.
 * both
 *     ```
       $args = array('posts_per_page' => 7, 'paged' => $current_page,'category' => $category_id, 'post_type' => 'post', 'suppress_filters' => false);
       $postslist = new WP_Query( $args );
       die ($postslist->max_num_pages);
       ```
   
 * (with category in the args array)
    and
 *     ```
       $args = array('posts_per_page' => 7, 'paged' => $current_page, 'post_type' => 'post', 'suppress_filters' => false);
       $postslist = new WP_Query( $args );
       die ($postslist->max_num_pages);
       ```
   
 * (without category in the args array)
    show 94 on the page.
 *  [Michael](https://wordpress.org/support/users/alchymyth/)
 * (@alchymyth)
 * [11 years, 6 months ago](https://wordpress.org/support/topic/problem-with-max_num_pages/#post-5448942)
 * can you provide the full code of the template?
 * please use the [pastebin ](http://pastebin.com/)– [http://codex.wordpress.org/Forum_Welcome#Posting_Code](http://codex.wordpress.org/Forum_Welcome#Posting_Code)
 *  Thread Starter [synthi100](https://wordpress.org/support/users/synthi100/)
 * (@synthi100)
 * [11 years, 6 months ago](https://wordpress.org/support/topic/problem-with-max_num_pages/#post-5448949)
 * This is the code in my index.php file. The code to output my posts is in a different
   file because I also need it for a load more ajax call, but I suppose that the
   code to output the posts is not necessary for this issue.
 * [code in pastebin](http://pastebin.com/jHfGCVh1)

Viewing 4 replies - 1 through 4 (of 4 total)

The topic ‘problem with max_num_pages’ is closed to new replies.

## Tags

 * [max_num_pages](https://wordpress.org/support/topic-tag/max_num_pages/)
 * [pagination](https://wordpress.org/support/topic-tag/pagination/)

 * In: [Fixing WordPress](https://wordpress.org/support/forum/how-to-and-troubleshooting/)
 * 4 replies
 * 2 participants
 * Last reply from: [synthi100](https://wordpress.org/support/users/synthi100/)
 * Last activity: [11 years, 6 months ago](https://wordpress.org/support/topic/problem-with-max_num_pages/#post-5448949)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
