Calling ‘have_posts()’ in a custom block returns false
-
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-demoIn 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)
- The topic ‘Calling ‘have_posts()’ in a custom block returns false’ is closed to new replies.