Title: Query all posts
Last modified: August 19, 2016

---

# Query all posts

 *  anonymized-3854925
 * (@anonymized-3854925)
 * [16 years, 3 months ago](https://wordpress.org/support/topic/query-all-posts/)
 * How do I query all posts rather than just by a specific category or tag? etc.
 * Basically I have a page that uses a custom template. On it I would like to pull
   in all of the posts for a site. If I use the standard:
 *     ```
       <?php if(have_posts()) : ?>
       <?php while(have_posts()) : the_post(); ?>
       <h2><?php the_title(); ?></h2>
       <?php the_excerpt(); ?>
       <?php endwhile; ?>
       <?php endif; ?>
       ```
   
 * Then it just gets the content for that particular page.
 * Is there some way I can use the query_posts function to do this?
 * Thanks.

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

 *  [esmi](https://wordpress.org/support/users/esmi/)
 * (@esmi)
 * [16 years, 3 months ago](https://wordpress.org/support/topic/query-all-posts/#post-1454656)
 * Try adding:
 *     ```
       <?php
       $paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
       $args= array(
       	'posts_per_page' => -1,
       	'paged' => $paged
       );
       query_posts($args);
       ?>
       ```
   
 * just before the start of the Loop.
 *  Thread Starter anonymized-3854925
 * (@anonymized-3854925)
 * [16 years, 3 months ago](https://wordpress.org/support/topic/query-all-posts/#post-1454948)
 * thanks, but I ended up getting it to work by passing ‘showposts=-1’ as a parameter.
 *  [Safirul Alredha](https://wordpress.org/support/users/zeo/)
 * (@zeo)
 * [16 years, 3 months ago](https://wordpress.org/support/topic/query-all-posts/#post-1454949)
 * pealo86,
    showposts parameter is deprecated. Use `posts_per_page` instead. e.
   g ‘`posts_per_page=-1`‘
 * esmi,
    ‘paged’ is not required since ‘`posts_per_page=-1`‘ will show all post
   in a single page.

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

The topic ‘Query all posts’ is closed to new replies.

 * 3 replies
 * 3 participants
 * Last reply from: [Safirul Alredha](https://wordpress.org/support/users/zeo/)
 * Last activity: [16 years, 3 months ago](https://wordpress.org/support/topic/query-all-posts/#post-1454949)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
