Title: SQL error when adding new post
Last modified: August 20, 2016

---

# SQL error when adding new post

 *  [djeyewater](https://wordpress.org/support/users/djeyewater/)
 * (@djeyewater)
 * [14 years, 11 months ago](https://wordpress.org/support/topic/sql-error-when-adding-new-post/)
 * I just upgraded my wordpress from 3.1.2 to 3.1.3. The upgrade was done by replacing
   the existing installation folder with the latest version, not using wordpress’
   built in upgrade facility.
 * After copying across the new version, I visited the admin area, but didn’t get
   a message about the database needing to be upgraded. After investigating I understand
   that this is because the database version is the same for 3.1.2 and 3.1.3, and
   so didn’t need to be upgraded.
 * Now when I click to add a new post, the new post page opens, but at the top of
   the page it says:
 * > 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 ‘AND ( (post.post_status=’inherit’ AND post.post_’ at line 5]
   >  SELECT*,
   > parent.post_status FROM wp_posts parent, wp_posts post WHERE (parent.post_status
   > =’publish’ OR parent.post_status=’private’) AND post.ID= AND ( (post.post_status
   > =’inherit’ AND post.post_parent=parent.ID) OR (parent.ID=post.ID) ) AND post.
   > post_type!=’nav_menu_item’ AND post.post_type!=’revision’ AND post.post_type!
   > =’attachment’
 * Can anyone help me with fixing this error?
 * Thanks
 * Dave

Viewing 7 replies - 1 through 7 (of 7 total)

 *  [esmi](https://wordpress.org/support/users/esmi/)
 * (@esmi)
 * [14 years, 11 months ago](https://wordpress.org/support/topic/sql-error-when-adding-new-post/#post-2137972)
 * Do you have a pre-upgrade database backup?
 *  Thread Starter [djeyewater](https://wordpress.org/support/users/djeyewater/)
 * (@djeyewater)
 * [14 years, 11 months ago](https://wordpress.org/support/topic/sql-error-when-adding-new-post/#post-2137994)
 * I do, would you suggest replacing the database with the pre-upgrade backup?
 *  [esmi](https://wordpress.org/support/users/esmi/)
 * (@esmi)
 * [14 years, 11 months ago](https://wordpress.org/support/topic/sql-error-when-adding-new-post/#post-2138012)
 * First try:
    – switching to the Twenty Ten theme
 * – [resetting the plugins folder](http://codex.wordpress.org/FAQ_Troubleshooting#How_to_deactivate_all_plugins_when_not_able_to_access_the_administrative_menus.3F)
   by FTP or phpMyAdmin.
 * – re-uploading all files & folders – **except** the wp-content folder – from 
   a **fresh** download of WordPress.
 * – running an upgrade manually using wp-admin/upgrade.php.
 *  Thread Starter [djeyewater](https://wordpress.org/support/users/djeyewater/)
 * (@djeyewater)
 * [14 years, 11 months ago](https://wordpress.org/support/topic/sql-error-when-adding-new-post/#post-2138068)
 * Thanks for the help, I have followed your advice and think I have narrowed it
   down to the relevanssi plugin. I’ve added the relevanssi tag to this thread now,
   so hopefully someone who knows about that plugin will find this thread to help
   out.
 *  [Mikko Saari](https://wordpress.org/support/users/msaari/)
 * (@msaari)
 * [14 years, 11 months ago](https://wordpress.org/support/topic/sql-error-when-adding-new-post/#post-2138210)
 * Well that is indeed SQL code from Relevanssi, but I don’t know what’s wrong with
   your site, I’ve had no trouble with Relevanssi with either 3.1.2 or 3.1.3.
 *  Thread Starter [djeyewater](https://wordpress.org/support/users/djeyewater/)
 * (@djeyewater)
 * [14 years, 10 months ago](https://wordpress.org/support/topic/sql-error-when-adding-new-post/#post-2138256)
 * I did some more investigating, and the error only occurred when I had another
   plugin activated. This other plugin used $wpdb->show_errors();
 * I tried a brand new installation of wordpress with new database and new download
   of relevanssi, and added $wpdb->show_errors(); to the relevanssi.php file. The
   error occurs when this is added, so it seems there is a bug with relevanssi, 
   just usually the error is hidden.
 * Whether it is worth fixing an error that is probably hidden for all users I will
   leave up to the developers, and I understand if they would rather concentrate
   on other things.
 *  [Mikko Saari](https://wordpress.org/support/users/msaari/)
 * (@msaari)
 * [14 years, 10 months ago](https://wordpress.org/support/topic/sql-error-when-adding-new-post/#post-2138264)
 * Hmm, I checked this out and the problem is that there’s a value missing from 
   the SQL query. Looks like a fix introduced in the latest version causes this 
   error…
 * Actually, this is an interesting bug – for some reason WordPress calls a hook
   when the add post page is opened, when the hooks should be fired only after editing
   a post. I wonder if this is actually a WordPress bug… I’ll have to investigate.

Viewing 7 replies - 1 through 7 (of 7 total)

The topic ‘SQL error when adding new post’ is closed to new replies.

## Tags

 * [Database Error](https://wordpress.org/support/topic-tag/database-error/)
 * [sql-error](https://wordpress.org/support/topic-tag/sql-error/)

 * In: [Fixing WordPress](https://wordpress.org/support/forum/how-to-and-troubleshooting/)
 * 7 replies
 * 3 participants
 * Last reply from: [Mikko Saari](https://wordpress.org/support/users/msaari/)
 * Last activity: [14 years, 10 months ago](https://wordpress.org/support/topic/sql-error-when-adding-new-post/#post-2138264)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
