WordPress.org

Ready to get started?Download WordPress

Forums

Why? (A Wordpres/logic/PHP question) (2 posts)

  1. WWDay3
    Member
    Posted 5 years ago #

    I was debugging a new theme I downloaded. The theme came with it's own Tags page (tags.php). The issue was no posts were showing up on the page. So, I went about debugging it.

    At one point I thought I'd check to see if have_posts() actually said it "had posts". so, right before the "if (have_posts())" I added

    echo have_posts();

    I didn't know if I'd get a value displayed or not, but it was worth a try. Imagine my surprise when the next time the page was displayed, it had posts on it.

    Wanting to make sure I wasn't seeing things, I then removed the echo statement and re-saved the page. On the next page refresh the posts were again missing.

    So, can someone explain to me what happened? How could adding the

    echo have_posts();

    right before the "if" have made the script suddenly work?

    And should I leave the echo there, or will it cause problems down the road? Should I remove it and figure out something else?

    Thanks

  2. Samuel Wood (Otto)
    Tech Ninja
    Posted 5 years ago #

    Without knowing the code that's around it, I can't tell you why it changed things. have_posts() in itself does next to nothing.

Topic Closed

This topic has been closed to new replies.

About this Topic