How to bulk edit a meta_value with mysql query

On my wordpress I have a little over 1000 posts which I’m looking to update a certain meta_vale of a particular meta_key and was wondering how I can do this with mysql. The meta_key I need to update is “Crafting” and I want to update every meta_value that currently has 40 / 400 (Golden) to just 400. “Crafting” has other values so I only want to update the ones that have the 40 / 400 (Golden) meta_value to 400.

What I’ve found so far but need some help finishing the query.

Read More
REPLACE INTO `wp_postmeta` (
  `meta_id`
, `post_id`
, `meta_key`
, `meta_value`
)
SELECT
      `meta_id`
    , `post_id`
    , "Crafting"
    , "40 / 400 (Golden)" -- assuming all posts to be set the same

After this I’m not really sure how what to.

Related posts

Leave a Reply

1 comment

  1. Assuming I’m understanding your question, you want to update the meta_value field to 400 in all posts that have meta_key = 'crafting' and meta_value = '40 / 400 (Golden)'?

    If so, a simple Update statement will work:

    update wp_postmeta
    set meta_value = '400'
    where meta_value = '40 / 400 (Golden)'
        and meta_key = 'Crafting'