Support » Fixing WordPress » Database error when adding new posts

  • Resolved murtrd


    Seemingly out of nowhere, I can’t publish new posts or set featured images. When I go to the admin panel -> add new, I have a “submit for review” button instead of publish, and when I click set featured image, there is no “use this as featured image” link. I’ve been debugging the crap out of this, checked my debug.log, and noticed the following error:

    [14-May-2012 14:54:02] WordPress database error Unknown column ” in ‘field list’ for query INSERT INTO ums_wp_posts () VALUES (”) made by wp_create_post_autosave, _wp_put_post_revision, wp_insert_post

    Debugged some more, and found that in wp-admin/post-new.php if I pass get_default_post_to_edit($post_type, false) instead of true (with the second parameter being $create_in_db via wp-admin/includes/post.php), I get the appropriate buttons. Meaning somewhere in this block of code (wp-admin/includes/post.php lines 418-427):

    if ( $create_in_db ) {
    		// Cleanup old auto-drafts more than 7 days old
    		$old_posts = $wpdb->get_col( "SELECT ID FROM $wpdb->posts WHERE post_status = 'auto-draft' AND DATE_SUB( NOW(), INTERVAL 7 DAY ) > post_date" );
    		foreach ( (array) $old_posts as $delete )
    			wp_delete_post( $delete, true ); // Force delete
    		$post_id = wp_insert_post( array( 'post_title' => __( 'Auto Draft' ), 'post_type' => $post_type, 'post_status' => 'auto-draft' ) );
    		$post = get_post( $post_id );
    		if ( current_theme_supports( 'post-formats' ) && post_type_supports( $post->post_type, 'post-formats' ) && get_option( 'default_post_format' ) )
    			set_post_format( $post, get_option( 'default_post_format' ) );

    I’m getting an error, because I’m trying to insert blank data into a column with no name, which obviously makes no sense. Has anyone run into this? Any idea how to fix this? The site has been working fine for months, I haven’t installed any new plugins, and all of a sudden this is happening.

Viewing 2 replies - 1 through 2 (of 2 total)
  • esmi


    Forum Moderator

    Have you tried:

    – deactivating all plugins to see if this resolves the problem. If this works, re-activate the plugins one by one until you find the problematic plugin(s).

    – switching to the Twenty Eleven theme to rule out any theme-specific problems.

    resetting the plugins folder by FTP or PhpMyAdmin. Sometimes, an apparently inactive plugin can still cause problems.

    – re-uploading the wp-admin and wp-includes folders from a fresh download of WordPress.

    It wasn’t really an option to deactivate all plugins at once and change themes since it would ruin the entire layout of the site. I ended up finding out the cause though. A plugin we had installed used the wp_insert_post_data filter and did not return $data, so in wp-includes/post.php::wp_insert_post, the result of $data was an empty array, and mysql was confused.

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Database error when adding new posts’ is closed to new replies.