have_posts() returning nothing or infinite loop

I am simply trying to learn how to use “The Loop”. I have tried using this PHP snippet, but nothing shows on the page at all. Not even the very top echo “hi”.

echo “hi”;
if (have_posts()){
echo “has posts”;
while (have_posts()){
the_post();
echo(“hi, this is ” . the_title());
} // end while
} // end if

In fact, I think it causes an infinite loop, as after I update my PHP snippet and reload the page calling it, it sits there loading forever, and I can’t even get back in to my Admin page until about 10 minutes later.

I absolutely have posts, and can’t square as to why this (seemingly simple) loop isn’t working. Removing everything except the top echo “hi” actually shows “hi” on the page. Adding the loop seems to cause an error I assume?

Read more here:: have_posts() returning nothing or infinite loop

Leave a Reply

Your email address will not be published. Required fields are marked *