Do we still need to include a “if (have_posts())” in templates?

When I look at WP::handle_404(), I think that the 404.php template will not be loaded, even if there are no posts, if:

  • We are on the homepage
  • It is a search
  • It is a taxonomy term that exists, but has no posts attached to it (and it’s not paged)
  • It is an author that exists, which has written no posts (yet) (and it’s not paged)

So in these template files, have_posts() can be useful.

Leave a Comment