Update field name without losing the value

So I have this photography website using ACF with flexible content. It has approximately 300 posts. Due to requirements,

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!

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!

Share Improve this question edited May 2, 2016 at 14:52 Sumit 4,8542 gold badges28 silver badges36 bronze badges asked May 2, 2016 at 14:35 JohannJohann 8674 gold badges14 silver badges31 bronze badges 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
Add a comment  | 

1 Answer 1

Reset to default -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'

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744679639a4587539.html

相关推荐

  • Update field name without losing the value

    So I have this photography website using ACF with flexible content. It has approximately 300 posts. Due to requirements,

    1天前
    20

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信