Make WordPress Core

Opened 14 years ago

Closed 13 years ago

Last modified 13 years ago

#5490 closed defect (bug) (worksforme)

Bad post URL gives database error instead of 404

Reported by: bobcat's profile Bobcat Owned by: westi's profile westi
Milestone: Priority: normal
Severity: normal Version: 2.5
Component: General Keywords:
Focuses: Cc:


If I enter a URL such as where there is no such post, I expect to get a 404 error. Instead, I get the following database error:

WordPress database error: [You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'ORDER BY p.post_date ASC LIMIT 1' at line 1]
SELECT p.ID, p.post_title FROM wp_posts AS p WHERE p.post_date > '' AND p.post_type = 'post' AND p.post_status = 'publish' AND p.ID != ORDER BY p.post_date ASC LIMIT 1

Change History (11)

#1 @santosj
14 years ago

This is a duplicate of another ticket.

#2 @santosj
14 years ago

Need ticket number before closing.

#3 @Bobcat
14 years ago

After doing some more research, I think my problem is that the _wp_old_slug redirect doesn't work. I see the old slug in the post_meta table, but the redirect doesn't happen.

#4 @Bobcat
14 years ago

It looks like the wp_old_slug_redirect redirect isn't happening because it's not being classified as a 404. And it's not a 404 because $wp_query->posts is not empty even though the post doesn't exist. $wp_query->posts has one element with only comment_status and ping_status, nothing else; there's no real post there.

#5 @westi
14 years ago

  • Owner changed from anonymous to westi
  • Status changed from new to assigned

#6 @DD32
14 years ago

Doesnt appear to be a problem on trunk for me. (Just tested)

Related: #5185, #5471

#7 @Bobcat
14 years ago

I just retested this with 2.5. I get a page with an empty post; HTTP response is '200'. Still not the '404' response I expected, which would allow an error message to be displayed to the user.

#8 @lloydbudd
14 years ago

  • Version changed from 2.3.1 to 2.5

#9 @Scott H
14 years ago

Works for me on trunk.

#10 @DD32
13 years ago

  • Resolution set to worksforme
  • Status changed from assigned to closed

I'm getting 404 errors from 404'ing posts and pages on 2.8 trunk, It could be a theme issue that causes the empty post.

#11 @jacobsantos
13 years ago

  • Milestone 2.9 deleted
Note: See TracTickets for help on using tickets.