【问题标题】:How to update table value in wordpress with update query?如何使用更新查询更新 wordpress 中的表值?
【发布时间】:2020-06-02 05:17:12
【问题描述】:

这是代码,我正在为发布数据用户电子邮件更新 wp_users 表的列名 custom_status。插入工作正常,但更新查询不起作用。

代码在这里:

if (isset($_POST["email_type"]) == 'News' ) {
    $wpdb->update('wp_users', array('custom_status' => 'News'), WHERE, array('user_email' => $_POST["user_email"] ));
}

感谢您的建议。

【问题讨论】:

  • 您是否遇到任何错误? update 的文档说需要第三个 where 参数。
  • 不,到目前为止没有任何错误。希望查询是正确的。请你检查一下。
  • 在不知道您要达到的目标的情况下,我无法再检查了。您是否尝试为所有用户设置custom_status?还是针对单个用户?查看documentation 中的update,特别是where 参数。
  • 抱歉编辑问题。
  • 我已经编辑了这个问题。通过邮件 ID 的 post 数据更新特定的 col。

标签: php mysql wordpress wordpress-theming


【解决方案1】:

您应该添加第三个参数,例如您将更新哪一行:

if (isset($_POST["email_type"]) == 'News' ) {
    $wpdb->update('wp_users', array('custom_status' => 'News'), array( 'ID' => 1 ));
}

希望能帮到你。

【讨论】:

  • 谢谢德米特里。它的工作。 col custom_status 已更新值为 News
猜你喜欢
  • 1970-01-01
  • 2021-11-12
  • 1970-01-01
  • 2017-04-26
  • 1970-01-01
  • 1970-01-01
  • 2017-12-19
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多