简体   繁体   English

将现有的元值复制到新的元键名称 - WordPress

[英]copy an existing meta_value to a new meta_key name - WordPress

I am trying to copy a meta_key and the corresponding meta_value to a new row in the wp_postmeta table where the meta_key gets a new name but with the original meta_value .我正在尝试将 meta_key 和相应的 meta_value 复制到wp_postmeta表中的新行,其中 meta_key 获得新名称但具有原始meta_value

I can copy one post with MySQL but this needs to be done for more than 300 posts so there must be a way to do this in a statement.我可以用 MySQL 复制一个帖子,但是这需要为 300 多个帖子完成,因此必须有一种方法可以在语句中执行此操作。

Example given: meta_key: postalCode meta_value: 1234AA needs to be copied to for the corresponding post id to meta_key: wpcf-adres meta_value:1234AA给出的例子:meta_key: postalCode meta_value: 1234AA 需要复制到对应的post id 到meta_key: wpcf-adres meta_value:1234AA

I have tried: update wp_postmeta set meta_key = 'postalCode' where meta_key = 'wpcf-adres'我试过:更新 wp_postmeta set meta_key = 'postalCode' where meta_key = 'wpcf-adres'

but this, of course, does not duplicate and keep the original meta_key but just renames it.但这当然不会复制并保留原始的 meta_key,而只是重命名它。

I hope someone can guide me in the right direction.我希望有人能指导我朝着正确的方向前进。

Thanks a lot for looking into it.非常感谢您的调查。

Kind regards亲切的问候

Wim维姆

update wp_postmeta  set meta_key = 'postalCode'  where meta_key = 'wpcf-adres'

This isn't my code, I saved it previously but it may be what you're after.这不是我的代码,我之前保存了它,但它可能是你想要的。 Switching the keys as needed.根据需要切换键。

 <?php
 // HOOK ON REGISTERING NEW USER/CUSTOMER
 add_action('user_register', 'mm_sync_phone_number' , 20, 1);    
 // HOOK ON PERSONAL OPTIONS UPDATE
 add_action('personal_options_update', 'mm_sync_phone_number' , 20, 1);
 // HOOK ON USER PROFILE UPDATE    
 add_action('edit_user_profile_update','mm_sync_phone_number' , 20, 1); 
 function mm_sync_phone_number( $user_id ) { 
 // GET PHONE NUMBER FROM OTHER FIELD
     $phone_number = get_user_meta( $customer_id, 'meta_key_of_other_phone_field', true );
 // UPDATE PHONE NUMBER IN BILLING PHONE NUMBER FIELD
 update_user_meta( $user_id, 'billing_phone',  $phone_number ); 
 }
 ?>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 在wordpress上更新新的数据库行以及meta_key和meta_value - Updating new database row along with meta_key and meta_value on wordpress 构造MySQL查询(meta_key / meta_value表) - Construct MySQL query ( meta_key/meta_value table) 通过在Wordpress中由meta_key和meta_value标识的自定义查询字符串来检索发布 - Retrieve Post by Custom Query String identified by meta_key and meta_value in Wordpress 如果WordPress中的meta_key = x和meta_value = y,如何显示图像? - How can I display an image if the meta_key=x AND meta_value=y in WordPress? 使用带有Ajax的select元素按WordPress中的一个meta_key和两个meta_value过滤帖子 - Filter posts by one meta_key and two meta_value in WordPress using a select element with Ajax WPDB查询-根据_meta_key返回meta_value - WPDB Query - Return meta_value based on _meta_key MySQL:搜索一个简单的表,但将WordPress&#39;wp_usermeta&#39;表与meta_key / meta_value组合 - MySQL: Searching one simple table, but combining the WordPress 'wp_usermeta' table with meta_key/meta_value 如何通过meta_value和meta_key检索meta_values的结果? - How to retrieve results of meta_values by meta_value and meta_key? 在 wp_postmeta 中更新/插入 meta_key 和 meta_value - Update/insert meta_key and meta_value in wp_postmeta Sql 查询以排除 meta_value where meta_key = x on SUM for WooCommerce - Sql query to exclude meta_value where meta_key = x on SUM for WooCommerce
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM