Title: paginate query_posts
Last modified: August 20, 2016

---

# paginate query_posts

 *  [ke vinritt](https://wordpress.org/support/users/ke-vinritt/)
 * (@ke-vinritt)
 * [14 years, 8 months ago](https://wordpress.org/support/topic/paginate-query_posts/)
 * I am using custom post types for an ‘events’ page. The events are ordered by 
   their date. Iam using the query_posts function to do this.
    `<?php query_posts('
   post_type=events&meta_key=date&orderby=meta_value&order=ASC&posts_per_page=5');?
   >` However, is there a way to add pagination? I want to show 5 events per page
   and then paginate. Also, is there a way to delete past date posts? Thanks

Viewing 1 replies (of 1 total)

 *  [vtxyzzy](https://wordpress.org/support/users/vtxyzzy/)
 * (@vtxyzzy)
 * [14 years, 8 months ago](https://wordpress.org/support/topic/paginate-query_posts/#post-2314902)
 * Pagination requires three things:
    1. Allowing the viewer to select a page number.
    2. Detecting the requested page number.
    3. Using the page number in the query.
 * The first part can be done using the built-in [WP function paginate_links()](http://codex.wordpress.org/Function_Reference/paginate_links)
   or a plugin such as [WP-PageNavi](http://wordpress.org/extend/plugins/wp-pagenavi/).
 * Part two is done by retrieving the query variable ‘page’:
 * `<?php $paged = (get_query_var('page')) ? get_query_var('page') : 1; ?>`
 * Part three is done by adding the ‘paged’ variable to the query. There are two
   formats commonly used to pass the argument to query_posts(): a query string or
   an array. The string method is similar to this:
 *     ```
       query_posts("cat=23&posts_per_page=5&paged=$paged");
       ```
   
 * The array arguments method looks like this:
 *     ```
       $args = array(
          'cat' => 23,
          'posts_per_page' => 5,
          'paged' => $paged
       );
       query_posts($args);
       ```
   

Viewing 1 replies (of 1 total)

The topic ‘paginate query_posts’ is closed to new replies.

## Tags

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

 * In: [Fixing WordPress](https://wordpress.org/support/forum/how-to-and-troubleshooting/)
 * 1 reply
 * 2 participants
 * Last reply from: [vtxyzzy](https://wordpress.org/support/users/vtxyzzy/)
 * Last activity: [14 years, 8 months ago](https://wordpress.org/support/topic/paginate-query_posts/#post-2314902)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
