Forums

The forums ran from 2008-2020 and are now closed and viewable here as an archive.

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

  • This topic is empty.
Viewing 9 posts - 1 through 9 (of 9 total)
  • Author
    Posts
  • #30460
    cjk
    Member

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


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



    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

    #78807
    Bob
    Member

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

    #78808
    Chris Coyier
    Keymaster

    &posts_per_page=-1

    #78810
    cjk
    Member

    Bob,

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

    Chris,

    LOL! 1 post is even sillier!

    #78811
    jamygolden
    Member

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

    #78813
    Bob
    Member

    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.

    #78816
    cjk
    Member

    OOPS! My apologies then! ;-)

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

    #78536
    Chris Coyier
    Keymaster

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

    #78079
    cjk
    Member

    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)
  • The forum ‘Back End’ is closed to new topics and replies.