at the top of the main loop, have_posts() and is_404() are mutually exclusive.
That is true sometimes, but not always. More specifically, it can be false when a non-permalink URL seeks a non-existent post. For example, /?p=-1.
Issue a 404 if a permalink request doesn’t match any posts. Don’t issue a 404 if one was already issued, if the request was a search, or if the request was a regular query string request rather than a permalink request.
Now it makes sense that the single.php template file would check have_posts(). Let the healing begin.
(Are there any documented examples of this bug occurring outside of single.php?)
Tags: correction
January 11, 2008 at 8:18 pm |
I had sort of forgotten about this. I would consider it extra strength usage. Which is good!
So if
/?page_id=9999is a regular query for an invalid page, shouldn’t a 404 be issued, eg, sndbx.org/?page_id=9999? Perhaps we should tag this for Sandbox.January 11, 2008 at 8:40 pm |
Scott: Confirmed: the page.php template also needs
if ( have_posts() ). Thanks!I was working on a patch to add Sandbox to core when this problem resurfaced. That’s why this post.
I do not know why WordPress does not issue 404s for these queries and use the 404.php template. It is intentional but the reason is undocumented. Anybody know?
January 11, 2008 at 9:00 pm |
Glad you finally come clean
Though I thought you would have fix core to make your lie a truth. (If I recall that was partially done was an example of trying to view a draft when logged out using the Sandbox was uncovered last year)
January 18, 2008 at 10:49 am |
Hacking core to prove yourself right is a completely valid course of action
January 24, 2008 at 3:55 pm |
[...] Andy Skelton: Apology: Not Useless Code really clicked with me. I can’t tell you how many times I’ve wanted to say “Um, you’re wrong” when people pontificate on their “expertise” of WordPress and blogging. Andy has done so beautifully in describing the WordPress Loop and how it isn’t useless coding. [...]