Grow your CSS skills. Land your dream job.

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

  • cjk
    # October 6, 2010 at 11:40 am

    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):


      < ?php
      $books = new WP_Query('category_name=recommended-books');
      while ($books->have_posts()) : $books->the_post();
      $permalink = get_permalink($books->ID);
      ?>
    • ">< ?php the_title(); ?>

    • < ?php endwhile; ?>

    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

    Bob
    # October 6, 2010 at 12:07 pm

    I believe you can set the property $post_count for WP_Query, as stated here. Perhaps try setting that to 10?

    # October 6, 2010 at 1:33 pm

    &posts_per_page=-1

    cjk
    # October 6, 2010 at 1:36 pm

    Bob,

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

    Chris,

    LOL! 1 post is even sillier!

    # October 6, 2010 at 1:38 pm

    Chris didn’t say 1 post per page, he said -1.

    Bob
    # October 6, 2010 at 1:49 pm

    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.

    cjk
    # October 6, 2010 at 1:52 pm

    OOPS! My apologies then! ;-)

    So, I’ll give it a whirl, but why -1?

    # October 8, 2010 at 7:12 pm

    -1 is WordPress’ way of saying “all”. Just the way it is.

    cjk
    # October 13, 2010 at 4:27 pm

    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?

Viewing 9 posts - 1 through 9 (of 9 total)

You must be logged in to reply to this topic.

*May or may not contain any actual "CSS" or "Tricks".