New posts defaulting to ‘0’ primary key

This is only my best guess. I can’t see a definitive answer with the information provided.


The primary key for wp_posts should be set to ID. The primary key is giving the error. Since ID is not defined in the query, it is likely that the AUTO_INCREMENT value has been set to 0, or is no longer incrementing.

I would look into your database and find the AUTO_INCREMENT value. I bet it’s set to 0 for some reason.

Take a backup of your database before making any changes to the database.

If the AUTO_INCREMENT value is set to 0, you want to set it to a value that hasn’t yet been reached. Go to wp_posts and find the highest value ID and set it to one more than that (or a few more than that, just to be safe).

For example, if the highest value ID in wp_posts is 1000:

ALTER TABLE wp_posts AUTO_INCREMENT = 1001;

If this is not the issue, ensure that the PRIMARY_KEY for the table is set to ID.