WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] No posts appearing on Page 2 with custom query (13 posts)

  1. m.busuttil
    Member
    Posted 1 year ago #

    I'm working on a ground-up WordPress build as a personal project that displays future posts as a calendar of upcoming events. To do that, I've had to play around with the query a bit, but my posts have been appearing fine.

    Today I moved forward to testing multiple pages, and I've discovered that, although the first page works fine, the second page just displays blank (aside from the header and footer). I found some code in another help topic that claimed to fix it, but it doesn't appear to be working - my second page still displays blank.

    Any chance someone can take a look and let me know what I'm doing wrong? It's a local build, but I've put my index.php up on Pastebin here. The relevant code starts around <div id="contentContainer">, but I thought I'd include it all just in case. Happy to answer any questions if that'll help.

  2. Rajesh Soni
    Member
    Posted 1 year ago #

    Try this modification, and note what you see when you're on page 2.

    http://pastebin.com/9z16eUdZ

  3. m.busuttil
    Member
    Posted 1 year ago #

    Still not getting anything on page 2. The xmp block is definitely loading on the home page - it has a built-in margin that pushes the header bar down - but not on /page/2/ -the header bar is at the top as per usual.

    I had a quick look at the page 2 code, and it looks like it's actually loading the 404 template, rather than the home page one. I'm now thinking that that might be the root cause of the problem - WordPress doesn't know that there's a Page 2, so it loads the 404 page, which doesn't have any of the posts on it because it's the 404 page.

    I don't know if that helps at all - I'm not sure how to "convince" WordPress that there's a second page.

  4. Rajesh Soni
    Member
    Posted 1 year ago #

    Site url please?

  5. m.busuttil
    Member
    Posted 1 year ago #

    The site is hosted locally at this point - I'm not intending to take it live for at least another couple of weeks.

  6. Rajesh Soni
    Member
    Posted 1 year ago #

    Ok are you certain you have set the permalink structure correctly?

  7. m.busuttil
    Member
    Posted 1 year ago #

    The only thing I've changed in the Permalink settings is to have it use Post Name instead of the default ?p=123 setting. (Is that what you mean, or is there another permalink thing that I should have done?)

  8. keesiemeijer
    moderator
    Posted 1 year ago #

    Why do use an offset for the first loop? try it with a query like this:

    <?php $paged = (get_query_var('paged')) ? get_query_var('paged') : 1; ?>
      <?php query_posts(array('posts_per_page' => 5, 'paged' => $paged, 'post_status' => 'future', 'order' => 'ASC')); ?>
  9. m.busuttil
    Member
    Posted 1 year ago #

    So, something kind of weird happened. It looks like it's all fixed, but I'm not exactly sure how; here's what I did.

    I went in and added some dummy published posts, in the hopes of forcing WordPress to think there was a second page. Sure enough, that worked - my second page loaded fine. Except that caused some problems of its own - the second page had a button that went to the third page, and the third page, which should have had a post on it, didn't load. So, not perfect, but maybe workable.

    Then I went in and changed the number of posts per page to 10 in the query. I intended to use 10 in the live site, so I figured I'd just troubleshoot the proper number rather than messing around with it too much.

    And it works now. The second page loads, and doesn't have a "next" button on it. I don't know what fixed it, exactly, but it appears to be fixed. Thanks very much for both your help.

  10. Rajesh Soni
    Member
    Posted 1 year ago #

    Have you tested a situation when the number of posts are worth more than two pages?

    Try setting the posts per page to a lesser number and test ALL pages.

  11. m.busuttil
    Member
    Posted 1 year ago #

    ...dammit.

    Yeah, OK. I went in and set Posts Per Page to 2. In theory, this should create 6 pages based on the number of future posts, or 3 pages based on the number of published posts. But it doesn't - it creates 2 pages, and then the third one 404s. In fact, this happens regardless of how many PPP I have - even if I set it to 1, the number of pages ends at 2.

    I'm starting to feel that my best option is going to be to rework the structure of the site so it sorts published posts by a custom field that displays the future event date - from my reading it looks like that would be an option, although not an ideal one. I'm kind of going crazy, because I can't tell what exactly is broken that needs to be fixed.

  12. Rajesh Soni
    Member
    Posted 1 year ago #

    Creating static pages is NOT a solution at all!

    Have you tried @keesiemeijer's suggestion?

  13. m.busuttil
    Member
    Posted 1 year ago #

    Yes - keesiemeijer's solution is what appeared to be working but is now apparently broken.

    I think I've not explained myself clearly - I'm not suggesting static pages. Rather, I'm thinking about doing a custom field in each post - something like 20130922, for 22 September 2013 - and then working the query to sort posts by that number. That way I'm not using future posts at all, and the pagination should go back to working. That's not an ideal solution, by any means, but if I can't get this to work...

Topic Closed

This topic has been closed to new replies.

About this Topic