0

So I have this photography website using ACF with flexible content. It has approximately 300 posts. Due to requirements, I need to update the name of some fields.

I've tried the following query:

UPDATE wp_postmeta SET meta_key = 'content_0_left_col_image_' WHERE meta_key = 'content_0_left_column_image';

UPDATE wp_postmeta SET meta_key = '_content_0_left_col_image_' WHERE meta_key = '_content_0_left_column_image';

Rows are affected (so everything's updated) but when I go ahead and try view any of the existing posts, the data inside that field is gone.

Any ideas what could be wrong?

Thanks!

1
  • 1
    The query you are doing is pretty much the right way to do it, except I'm guessing you didn't rename them correctly and you only need one query. What is the meta key you originally have and what is the new one you want? Also don't forget to update the declaration of the custom field once that query is run. Keep in mind that since your query has already ran, you already renamed some meta_keys, this is why they don't appear anymore.
    – Tofandel
    Commented Mar 11, 2020 at 16:34

1 Answer 1

-1

I hope I understand the question correctly

UPDATE `wp_postmeta` SET `meta_value` = replace(meta_value, 'old_value', 'new_value') WHERE `meta_key` LIKE 'your_key'

EDIT 1 : i forgot to mention : BACKUP YOUR DATABASE BEFORE ANY TRIAL

EDIT 2 : following comment : To copy from one field to another (I got a bit confused with your naming and which value you want where , so I post the generic sentence.

UPDATE `TABLE` SET `FIELD2` = `FIELD1'
1
  • 1
    No, the user is not trying to replace a meta value or rename a column, he is trying to rename a meta key.
    – Tofandel
    Commented Mar 11, 2020 at 16:33

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.