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

---

# Querying all posts

 *  Resolved [haagendazs1](https://wordpress.org/support/users/haagendazs1/)
 * (@haagendazs1)
 * [18 years, 4 months ago](https://wordpress.org/support/topic/querying-all-posts/)
 * Hi, I feel this problem is probably has a really simple solution but I’ve been
   trying for hours and nothing is working…
 * I have a dropdown menu of each category, and each item in the menu would lead
   you to each category’s archive. I just want a page that displays every post, 
   and that would be considered the “all” category. Obviously I don’t want to actually
   create an “all” category and mark every post as having this category. Is there
   some code snippet I can stick in category.php (which is the template I’m using
   to display the category archives) that can say something to the effect of “if
   I’m on (some page or some empty category) display every post”?
 * Thanks!

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

 *  Thread Starter [haagendazs1](https://wordpress.org/support/users/haagendazs1/)
 * (@haagendazs1)
 * [18 years, 4 months ago](https://wordpress.org/support/topic/querying-all-posts/#post-682820)
 * I forgot to mention what I’ve tried. The closest I got to getting it, is by doing
   this: I made a new page, ID=5, and made it use the category.php as its template.
   Then I made up a random category to exclude in query_post (lets say ID=5). Then,
   in category.php, before The Loop, I inserted something like this:
 * <?php if (is_page(‘5’)) : ?>
    <?php query_posts(“cat=-5”.”&posts_per_page=12″);?
   > <?php endif; ?>
 * This almost got the effect I wanted, since it just made a category page, essentially,
   that excluded a category that has nothing in it. However, when I pressed the 
   previous page links, the 12 posts shown in that previous page were identical 
   to the 12 posts shown in the first page. For some reason, every page would only
   show the 12 most recent posts instead of going further back and actually showing
   the last 12 posts, then the 12 before that, etc.
 *  [moshu](https://wordpress.org/support/users/moshu/)
 * (@moshu)
 * [18 years, 4 months ago](https://wordpress.org/support/topic/querying-all-posts/#post-682821)
 * 1. Isn’t your index (main, front) page doing just like that – showing “ALL”?
 * 2. Usually, query_posts breaks the next/prev navigation.
 *  Thread Starter [haagendazs1](https://wordpress.org/support/users/haagendazs1/)
 * (@haagendazs1)
 * [18 years, 4 months ago](https://wordpress.org/support/topic/querying-all-posts/#post-682859)
 * 1. Yes, it is. However I want a different page to be doing it as well, as an 
   archive. Any ideas? 🙂
 * 2. Dang. 🙁
 *  [moshu](https://wordpress.org/support/users/moshu/)
 * (@moshu)
 * [18 years, 4 months ago](https://wordpress.org/support/topic/querying-all-posts/#post-682862)
 * 1. Why would you want “duplicate content” – which, allegedly, is penalized by
   search engines?
 *  Thread Starter [haagendazs1](https://wordpress.org/support/users/haagendazs1/)
 * (@haagendazs1)
 * [18 years, 4 months ago](https://wordpress.org/support/topic/querying-all-posts/#post-682870)
 * 1. Ohh I don’t want to repost the whole post in the archives, its only the title
   and some stuff from each post’s custom fields, like the post’s rating or something
   like that.
 *  Thread Starter [haagendazs1](https://wordpress.org/support/users/haagendazs1/)
 * (@haagendazs1)
 * [18 years, 4 months ago](https://wordpress.org/support/topic/querying-all-posts/#post-683036)
 * Anyone have any ideas? 🙁
 *  [MichaelH](https://wordpress.org/support/users/michaelh/)
 * (@michaelh)
 * [18 years, 4 months ago](https://wordpress.org/support/topic/querying-all-posts/#post-683038)
 * Could you use `query_posts('posts_per_page=-1');` and not worry about prev/next
   navigation?
 *  [MichaelH](https://wordpress.org/support/users/michaelh/)
 * (@michaelh)
 * [18 years, 4 months ago](https://wordpress.org/support/topic/querying-all-posts/#post-683039)
 * Or develop your own loop using the [wpdb](http://codex.wordpress.org/wpdb) class
   and deal with the next/prev navigation in your logic.
 *  [Kafkaesqui](https://wordpress.org/support/users/kafkaesqui/)
 * (@kafkaesqui)
 * [18 years, 4 months ago](https://wordpress.org/support/topic/querying-all-posts/#post-683063)
 * You could create a Page (Write > Write Page) called… Category that just uses 
   a [custom Page template ](http://codex.wordpress.org/Pages#Creating_your_own_Page_Templates)
   implementing query_posts().
 * I do something similar on my site but don’t list every post! Just the categories
   with description and such. However, one can combine the idea of a Category Page
   with what I do on my ‘Archive’ Page:
 *     ```
       <?php
       $limit = get_option('posts_per_page');
       $paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
       query_posts('showposts=' . $limit . '&paged=' . $paged);
       $wp_query->is_archive = true; $wp_query->is_home = false;
       ?>
       ```
   
 * Notes:
 * `$limit` is assigned the ‘posts_per_page’ option from your WordPress settings,
   but can be changed to something else if you like:
 * `$limit = 20;`
 * These:
 *     ```
       $wp_query->is_archive = true;
       $wp_query->is_home = false;
       ```
   
 * after the query_posts() are important as they force posts_nav_link() (and so 
   pagination) to work, along with a few other helpful results gained for fooling
   WordPress into thinking we’re in the archive pages.
 * For the $paged stuff, see:
    [http://wordpress.org/support/topic/57912#post-312858](http://wordpress.org/support/topic/57912#post-312858)
 *  Thread Starter [haagendazs1](https://wordpress.org/support/users/haagendazs1/)
 * (@haagendazs1)
 * [18 years, 4 months ago](https://wordpress.org/support/topic/querying-all-posts/#post-683081)
 * Kafkaesqui: Thank you so much! Your method worked like a charm, I really appreciate
   your explanation.
 * MichaelH: Thanks for the tips, I suppose I could have done the posts_per_page
   =-1 method if I didn’t have an alternative. I’ll keep your ideas in mind 🙂
 *  [fishnyc](https://wordpress.org/support/users/fishnyc/)
 * (@fishnyc)
 * [18 years, 1 month ago](https://wordpress.org/support/topic/querying-all-posts/#post-683183)
 * AWESOME POST! Worked Perfectly! BRAVO!!!!
 *  [gverhoff](https://wordpress.org/support/users/gverhoff/)
 * (@gverhoff)
 * [17 years, 10 months ago](https://wordpress.org/support/topic/querying-all-posts/#post-683188)
 * This is almost what I need.
 * How can I exclude a couple of categories from this query?
 * Thanks in advance!

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

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

## Tags

 * [all](https://wordpress.org/support/topic-tag/all/)
 * [posts](https://wordpress.org/support/topic-tag/posts/)
 * [query](https://wordpress.org/support/topic-tag/query/)

 * In: [Fixing WordPress](https://wordpress.org/support/forum/how-to-and-troubleshooting/)
 * 12 replies
 * 6 participants
 * Last reply from: [gverhoff](https://wordpress.org/support/users/gverhoff/)
 * Last activity: [17 years, 10 months ago](https://wordpress.org/support/topic/querying-all-posts/#post-683188)
 * Status: resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
