treehouse : what would you like to learn today?
Web Design Web Development iOS Development

[Solved] Multiple Loop in WP for 404page, want full list of posts (not first 10 only)

  • Hi!

    There must be a more elegant way to handle this, but, I can't figure it out!

    Basically, I wish to create a sitemap on my 404 page, using multiple loops to grab the titles of posts by category and display in a list.

    This is the code I have used (in fact I use a new query 6 times, once for each category):

    <ul>
    <h2><a href="/blog/category/recommended-books/"> Book Reviews...</a></h2 >
    <ul>
    <?php
    $books = new WP_Query('category_name=recommended-books');
    while ($books->have_posts()) : $books->the_post();
    $permalink = get_permalink($books->ID);
    ?>
    <li><a href="<?php echo $permalink; ?>"><?php the_title(); ?></a></li>
    <?php endwhile; ?>
    </ul>
    </ul>


    Which works fine, except it only creates a list of the latest "10" posts and I would like the COMPLETE list of posts.

    The simple, and not so elegant way to handle this would be to add:

    &posts_per_page=9999
    to the new WP_Query string, and that works of course, however, does anyone know of a more elegant and less "hackish" solution to this?

    Cheers!
    Chris
  • I believe you can set the property $post_count for WP_Query, as stated here. Perhaps try setting that to 10?
  • &posts_per_page=-1
  • Bob,

    But I want the COMPLETE list of posts - not just 10!

    Chris,

    LOL! 1 post is even sillier!
  • Chris didn't say 1 post per page, he said -1.
  • We should have emoticon here that says: I'm with stupid so I can use that on myself. Sorry @cjk, I must've read wrong, I hope Chris' answer is helpfull for you.
  • OOPS! My apologies then! ;-)

    So, I'll give it a whirl, but why -1?
  • -1 is WordPress' way of saying "all". Just the way it is.
  • Thanks Chris,

    I would never have guessed and I didn't see anything in the Codex to suggest it.

    Odd though, in this case it says "all" yet when we use it in the regular loop for Categories, for example, -1 would be saying get all categories except #1. Yes?