Title: Query posts and pagination problem
Last modified: August 19, 2016

---

# Query posts and pagination problem

 *  [chavo](https://wordpress.org/support/users/chavo/)
 * (@chavo)
 * [15 years, 2 months ago](https://wordpress.org/support/topic/query-posts-and-pagination-problem/)
 * Sin WordPress 3.X I can’t figure out how to get pagination working with query_posts.
   With older versions I usually used querys_posts and everything works fine. But
   now, my code doesn’t works. I read a lot of possible solutions but no one works
   for me.
 * I place my code in archive.php and looks like this:
 *     ```
       <?php
       $cat = get_query_var('cat');
       $paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
       $sticky=get_option('sticky_posts');
       $args=array(
       'category__in'=> array($cat),
       'post__not_in' => $sticky,
       'paged'=>$paged,
       'posts_per_page' => 4
       );
       query_posts($args); ?>
       <?php // The Loop ?>
       <?php if (have_posts()) : ?>
       <?php $post = $posts[0]; // Hack. Set $post so that the_date() works. ?>
       <?php while (have_posts()) : the_post(); ?>
       // my stuff
       <?php endwhile; endif; ?>
       ```
   
 * According to WordPress 3.0.2 note
    _Pagination Note: You should set get\_query\
   _var( ‘page’ ); if you want your query to work with pagination. Since WordPress
   3.0.2, you do get\_query\_var( ‘page’ ) instead of get\_query\_var( ‘paged’ ).
   The pagination parameter ‘paged’ for WP\_Query() remains the same. _. So, I replace
   this: `$paged = (get_query_var('paged')) ? get_query_var('paged') : 1;` for this:`
   $paged = (get_query_var('page')) ? get_query_var('page') : 1;` I also tried with
   this: `$paged = (get_query_var('paged'));` Nothing works (it doesn’t show pagination
   links in fact).
 * I tried using a new WP_Query like this:
 *     ```
       <?php
       	$query = new WP_Query('category__in='.get_query_var('cat').'&posts_per_page=1&paged=' . get_query_var('page') );
       	 ?>
       ```
   
 * Not working.
 * The only way to get pagination working is setting amount of posts to show from
   admin panel. But that’s not what I want because I need to specify different amount
   of posts based on categories.
 * Anyone can help me?
 * Thanks in advance.
 * ps: sorry for my bad english

The topic ‘Query posts and pagination problem’ is closed to new replies.

## Tags

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

 * In: [Fixing WordPress](https://wordpress.org/support/forum/how-to-and-troubleshooting/)
 * 0 replies
 * 1 participant
 * Last reply from: [chavo](https://wordpress.org/support/users/chavo/)
 * Last activity: [15 years, 2 months ago](https://wordpress.org/support/topic/query-posts-and-pagination-problem/)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
