mysql - wordpress - 替换表中的元值
问题描述
我在数据库中有一个“usermeta”表。
并且有一些列,包括 meta_key 和 meta_value。
delivery_location(meta_key) 具有相同的 meta_value。
所以我想将当前的 meta_value 替换为 deliery_location 中的新值
(70982, 20, 'delivery_location', 'a:61:{i:0;s:47:"{lat:32.89030473256227, lng:-96.96264851172401}";i:1;s:47:"{lat:32.89359300394015, lng:-96.94936752319336}";i:60;s:0:"";}'),
我的问题是如何在 mysql 中一次替换所有相同的 meta_values?
解决方案
您可以使用get_users()获取所有用户。检查下面的代码。代码进入您的活动主题functions.php 文件。
function update_all_user_delivery_location(){
$users = get_users( array( 'fields' => array( 'ID' ) ) );
foreach ( $users as $key => $user ) {
$delivery_location = get_post_meta( $user->ID, 'delivery_location', true );
// modify your code here
update_post_meta( $user->ID, 'delivery_location', $delivery_location );
}
}
add_action( 'init', 'update_all_user_delivery_location', 10, 1 );
推荐阅读
- stored-procedures - 带有 Unicode 字符的 MFC ODBC 存储过程参数
- javascript - 将javascript代码与blazor结合的问题
- javascript - 如何在本机反应中根据状态值在道具内设置条件?
- openrefine - OpenRefine JSON 中的模式匹配
- gnuplot - 为图表指定特定大小
- buildroot - 如何解决错误:包在没有正确 RPATH 的情况下安装可执行文件
- sql - Snowflake SQL 错误:插入查询:期待 DATE,但得到 NUMBER(9,0) 列
- bash - 使用重命名递归地将前缀附加到所有文件
- c# - WPF:安装项目/发布版本中的 LibVLCSharp 集成
- c++ - QT中qdialog的字体在哪里设置?