【问题标题】:wordpress - replace meta values in tablewordpress - 替换表中的元值
【发布时间】:2021-07-03 20:24:56
【问题描述】:

我在 db 中有一个“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 中一次替换所有相同的元值?

【问题讨论】:

标签: mysql database wordpress key-value meta


【解决方案1】:

您可以使用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 );

【讨论】:

  • 非常感谢...~~~~
猜你喜欢
  • 2015-08-11
  • 2021-08-10
  • 2013-04-01
  • 2014-03-14
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多