• Resolved markcummins

    (@comminski)


    Hi, I noticed something different happening on my website when testing WP 6.4-rc3.

    I had a custom block which used the ‘have_posts()’ function. In WP 6.3, it worked fine, but after updating to WP 6.4-rc3, it doesn’t work the same way anymore.

    If I call ‘have_posts()’, it used to return true, and now it returns false. If I call it a second time, it does return true though.

    What was happening for me was that I had two of these blocks on the page, and only the second block would show on the front-end. Maybe I should not be using it like this though?

    I created a demo plugin to demonstrate this:
    https://github.com/markcummins/wp-sample-block-demo

    In the repo, I added a readme which has more details on how to replicate the issue.

    (p.s. I noticed that the reason it works on re-calling the function is because when you call ‘have_posts()’ the first time, it calls ‘rewind_posts()’ after it runs)

    • This topic was modified 11 months, 3 weeks ago by markcummins.
Viewing 4 replies - 1 through 4 (of 4 total)
  • Moderator jordesign

    (@jordesign)

    Hi @comminski – thanks for reporting this. In terms of getting this in front of the eyes of developers (especially as it is a change in WP6.4) – could you please open a Bug Report in the Gutenberg GitHub repo?

    https://github.com/WordPress/gutenberg/issues/new/choose

    Moderator Marius L. J.

    (@clorith)

    This is partially expected behavior, as WordPress 6.4 changes how templates outside the post content are loaded.

    While the fact that it returns true when you call the function again is a bit unexpected, but a plugin would also not call have_posts() multiple times in a row like that, so for now this seems like an unhandled edge case.

    A developers note is being published to ensure this change is communicated, once it has been published, I’ll make sure to add a link to it here as well, and if there’s any unexpected interactions that users encounter due ot this change, we would love to hear about them as well.

    Thread Starter markcummins

    (@comminski)

    Hi, sorry I didn’t check back up on this and thanks for the response. For me, I used rewind_posts() before calling have_posts(), and that solved the issue that I was having. As you say though, I shouldn’t be calling it twice anyway.

    I just wanted to highlight it before wp 6.4 launched in case it was a bug, but if it’s expected behavior, then it makes sense to close the issue.

    Sandy Nichols

    (@sandysandynicholsnet)

    Thank you for this thread! I also had this problem and rewind_posts() has helped for now.

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Calling ‘have_posts()’ in a custom block returns false’ is closed to new replies.