The "could not insert post into the database" error in WordPress stops you from publishing posts, uploading media, or saving changes - and it can appear without warning. The error typically points to one of four causes: a temporary server overload, insufficient PHP memory, a plugin or theme conflict, or a misconfigured server. In some cases, a corrupted WordPress database table is the culprit.
This guide covers 7 fixes in order of likelihood, starting with the quickest checks. If you're seeing the attachment variant - "could not insert attachment into the database" - skip to Step 6, which addresses that specific error separately.
Step 1: Check if the Issue is Temporary
Before making any changes, confirm whether the error is temporary. A sudden spike in traffic, a server running low on resources, or a brief database connection drop can all cause this error to appear and then disappear on its own within a few minutes.
Signs the issue may be temporary:
- The error appeared suddenly after a period of normal operation
- Your WordPress dashboard is still accessible and other features work
- The error resolves after refreshing or waiting 5 minutes
If the error goes away on its own, monitor for recurrence. Repeated temporary errors usually signal that your server is consistently running at capacity. In that case, consider moving from shared hosting to a VPS or cloud server. Services like Cloudways offer managed cloud hosting that handles resource scaling automatically.
If the error persists after waiting, move to the next step.
Step 2: Add More PHP Memory
Insufficient PHP memory is one of the most common causes of this error. When WordPress doesn't have enough memory to complete a database write operation, it fails and returns the "could not insert post" message.
To increase the PHP memory limit, access your wp-config.php file via FTP or your hosting file manager. Add the following line directly before the line that reads /* That's all, stop editing! Happy publishing. */:
define( 'WP_MEMORY_LIMIT', '512M' );
If that line already exists in your file, change the current value (e.g., 256M) to 512M. Save the file and try publishing again. Low PHP memory is also a common cause of the HTTP 500 error in WordPress, so this fix often resolves multiple issues at once.
Note: If your hosting plan has a hard cap on PHP memory below 512M, this change will have no effect - you'll need to contact your host or upgrade your plan.
Step 3: Deactivate Plugins
A plugin or theme conflict can block database writes. If you recently updated or installed a plugin, start there: deactivate it and try publishing again. If the error disappears, that plugin is the culprit.
If you're not sure which plugin is causing the problem, deactivate all plugins at once and reactivate them one by one:
- Go to Plugins > Installed Plugins.
- Select all plugins using the checkbox at the top.
- From the Bulk Actions dropdown, choose Deactivate and click Apply.
- Try publishing a post. If it works, reactivate plugins one at a time until the error returns - the last plugin reactivated is the conflict.
If plugins aren't the issue, repeat the same process with your theme. Switch temporarily to a default WordPress theme (Twenty Twenty-Four) and test again. Always keep a default WordPress theme installed as a fallback for exactly this reason.
Step 4: Server Configuration
Some server configurations block WordPress from writing to the database, particularly on restrictive shared hosting environments. Issues to check:
- Database user permissions: Your WordPress database user must have INSERT, UPDATE, and DELETE privileges. If permissions were recently changed (by you or your host), this can cause database write failures.
- MySQL/MariaDB version mismatch: Some older WordPress installs break after a host upgrades the database server version. Ask your host if a recent database update occurred.
- Max allowed packet size: If you're trying to insert very large posts or media, the MySQL max_allowed_packet setting may be too low. Your host can increase this.
Contact your hosting support team with the specific error message and the time it occurred. Most hosts can pull server logs to identify whether the issue is configuration-related.
Step 5: Repair the WordPress Database
If your WordPress database tables have become corrupted (which can happen after a server crash or failed update), WordPress will fail to write new records, producing the "could not insert post" error. WordPress has a built-in repair tool you can run without a plugin.
To enable it, add this line to your wp-config.php file (before the "stop editing" line):
define('WP_ALLOW_REPAIR', true);
Then visit https://yoursite.com/wp-admin/maint/repair.php in your browser. You'll see options to Repair Database or Repair and Optimize Database. Run the repair, then remove the define('WP_ALLOW_REPAIR', true); line from your wp-config.php immediately after - leaving it in place means anyone can access the repair tool without logging in.
Alternatively, you can repair tables directly from your hosting control panel using phpMyAdmin: select your WordPress database, check all tables, and use the "Repair table" option from the operations dropdown.
Step 6: Fix "Could Not Insert Attachment Into the Database"
The attachment variant of this error - "could not insert attachment into the database" - appears when you upload media files (images, PDFs, videos) to WordPress. It's a separate code path from the post insertion error, and the causes sometimes differ.
The most common causes of the attachment error:
- Uploads directory permissions: WordPress needs write access to
/wp-content/uploads/. If file permissions are set incorrectly (should be 755 for directories, 644 for files), uploads fail at the database level. Fix via FTP: right-click the uploads folder, select "File permissions," and set to 755 recursively. - PHP memory limit: Image processing during upload consumes more memory than a text post insertion. If you're only seeing this error on media uploads and not on post saves, increase PHP memory to 512M as in Step 2.
- Blocked MIME types: Some security plugins block certain file types from being uploaded, which causes a database insertion failure. Temporarily deactivate security plugins (Wordfence, iThemes Security, etc.) and retry the upload.
- Corrupted wp_postmeta table: The attachment error is often tied specifically to the
wp_postmetatable. Run the database repair from Step 5 and focus on this table if phpMyAdmin shows it as corrupted. - File size limit: If the file exceeds your PHP
upload_max_filesizeorpost_max_sizelimit, WordPress may record a partial database entry and throw this error. Your host can raise these limits, or you can add them to yourphp.inior.htaccessfile.
The quickest diagnostic: try uploading a small (under 100KB) JPEG and a larger file separately. If the small file works but large ones don't, you have a file size or memory limit issue. If all uploads fail regardless of size, check directory permissions first.
Step 7: Check Your Error Logs
If none of the above steps resolve the error, enable WordPress debug logging to capture the underlying database error. Add these lines to wp-config.php:
define('WP_DEBUG', true);
define('WP_DEBUG_LOG', true);
define('WP_DEBUG_DISPLAY', false);
Reproduce the error, then check /wp-content/debug.log for the actual MySQL error message. The log entry will tell you exactly which database table failed and why - which narrows down whether it's a permissions issue, a corrupted table, or a MySQL error code you can look up directly. For a full guide to reading these logs, see how to check the PHP error log on WordPress.
How Long Does It Take to Fix This WordPress Error?
Most cases resolve within 15–30 minutes once you identify the cause:
| Cause | Time to Fix | Skill Level Needed |
|---|---|---|
| Temporary server issue | Resolves itself in 5–10 min | None - just wait |
| PHP memory limit | 2–5 minutes (one wp-config.php edit) | Basic FTP access |
| Plugin conflict | 10–20 minutes (deactivate and test) | WordPress admin access |
| Server configuration | 30–60 minutes (requires hosting support) | Hosting support ticket |
| Database corruption | 5–15 minutes (run the repair tool) | Basic wp-config.php editing |
| Attachment permissions | 5–10 minutes (FTP permission change) | FTP client access |
Final Word: Could Not Insert Post Into the Database WordPress Error
This error almost always has a fixable cause - it's rarely a sign of serious data loss. Work through the steps above in order: check if it's temporary, increase PHP memory, deactivate plugins, review server configuration, run the database repair, and if you're hitting the attachment variant specifically, check upload directory permissions and MIME type blocking. If the error persists after all seven steps, contact your hosting provider with the debug log output - that gives them exactly what they need to diagnose the server-side cause.
For a deeper look, see our complete guide to What Is WordPress?.
* read the rest of the post and open up an offer