{
  "$type": "site.standard.document",
  "content": {
    "$type": "site.standard.content.markdown",
    "text": "You're probably looking at this post because you've seen the error message `Updating failed. Could not update <field> in the database.` on a Wordpress site.\n\nI came across this recently while doing some work for a client. There are several ways to fix it. The first is to manually recreate each page from scratch. I started doing this, thinking it was something to do with the Gutenberg block editor. But I got frustrated, I didn't want to go through 50 odd pages and make this correction manually.\n\nI decided to look at the database itself to see if I could work out what the problem was. It turned out that the post meta table contained duplicate entries—where a single post had the same `meta_key` value.\n\nI found [this site (Use Wordpress)](https://usewordpress.com/snippets/how-to-find-duplicate-post-meta-in-wordpress/) which helped me drill down into the data, and identify problem posts. Reproducing below in case it ever goes offline.\n\nIf you think you might have this issue, run the following SQL query:\n\n```sql\nSELECT T1.post_id, T1.meta_key,  T1.meta_value, T1.meta_id, T2.post_id, T2.meta_key, T2.meta_value, T2.meta_id\nFROM wp_postmeta T1, wp_postmeta T2\nWHERE T1.post_id = T2.post_id\nAND T1.meta_value = T2.meta_value\nAND T1.meta_key = T2.meta_key\nAND T1.meta_id > T2.meta_id\n```\n\nIf you have results, then you should _back up your database_, and then run the following:\n\n```sql\nDELETE T1 FROM wp_postmeta T1\nINNER JOIN wp_postmeta T2\nWHERE T1.post_id = T2.post_id\nAND T1.meta_value = T2.meta_value\nAND T1.meta_key = T2.meta_key\nAND T1.meta_id > T2.meta_id\n```\n\nWith a bit of luck, your problem will be solved.",
    "version": "1.0"
  },
  "description": "How to fix this annoying Wordpress error which stops you from updating posts on your site.",
  "path": "/blog/updating-failed",
  "publishedAt": "2022-10-25T20:40:00.000Z",
  "site": "https://joeinn.es",
  "textContent": "You're probably looking at this post because you've seen the error message  on a Wordpress site.\n\nI came across this recently while doing some work for a client. There are several ways to fix it. The first is to manually recreate each page from scratch. I started doing this, thinking it was something to do with the Gutenberg block editor. But I got frustrated, I didn't want to go through 50 odd pages and make this correction manually.\n\nI decided to look at the database itself to see if I could work out what the problem was. It turned out that the post meta table contained duplicate entries—where a single post had the same  value.\n\nI found this site (Use Wordpress) which helped me drill down into the data, and identify problem posts. Reproducing below in case it ever goes offline.\n\nIf you think you might have this issue, run the following SQL query:\n\nIf you have results, then you should back up your database, and then run the following:\n\nWith a bit of luck, your problem will be solved.",
  "title": "Updating failed. Could not update in the database"
}