SQL Error
-
I started to get this SQL error when trying to view comments on a post. So I thought about posting how I solved it, since what I did was modifying a WP file.
The error was:
<b>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 post_date ASC LIMIT 1’ at line 1]
SELECT ID,post_title FROM wp_posts WHERE post_date > ” AND post_date < ‘2005-06-27 09:03:57’ AND post_status = ‘publish’ AND ID != ORDER BY post_date ASC LIMIT 1
</b>Solution:
in the /wp-include/ directory I edited the template-functions-link.php file
and in this line:
return @$wpdb->get_row("SELECT ID,post_title FROM $wpdb->posts $join WHERE post_date > '$current_post_date' AND post_date < '$now' AND post_status = 'publish' $sqlcat $sql_exclude_cats AND ID != $post->ID ORDER BY post_date ASC LIMIT 1");
<strong>I added single quotes to $Post->ID
</strong>return @$wpdb->get_row("SELECT ID,post_title FROM $wpdb->posts $join WHERE post_date > '$current_post_date' AND post_date < '$now' AND post_status = 'publish' $sqlcat $sql_exclude_cats AND ID != '$post->ID' ORDER BY post_date ASC LIMIT 1");
and now it's working, hope it helps someone else.
- The topic ‘SQL Error’ is closed to new replies.