Wordpress - $wpdb->insert - MySQL NOW()

标签 wordpress

是否有可能在 $wpdb->insert 调用中使用 MySQL NOW()?

当我使用以下代码时,NOW() 不起作用。

$data = array(
        'id' => NULL,
        'order' => serialize($_POST['data']['Order']),
        'created' => NOW(),
        'user_id' => $current_user->ID
    );

$wpdb->insert(ORDERS_TABLE, (array) $data );

最佳答案

我相信规范的方法是使用 WordPress current_time()函数传递它 'mysql' 作为第一个参数来指定 mysql 时间戳兼容格式(替代方法是 UNIX 时间戳格式)和 '1' 作为第二个参数来指定 GMT 时间(默认为本地),如下所示:

$data = array(
    'id' => NULL,
    'order' => serialize($_POST['data']['Order']),
    'created' => current_time('mysql', 1),
    'user_id' => $current_user->ID
);

$wpdb->insert(ORDERS_TABLE, $data);
current_time('mysql', 1)输出 2012-07-18 12:51:13 .
更多信息:http://codex.wordpress.org/Function_Reference/current_time

关于Wordpress - $wpdb->insert - MySQL NOW(),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8566603/

相关文章:

html - 如何使某个 p 类成为默认 p 类(用于 Wordpress 主题)

wordpress - 为外部链接永久添加 rel ="nofollow"和目标 ="_blank"

css - 仅在菜单中居中对齐一个元素(wordpress)

jquery - 不要在标题类中打断单词

子域到根迁移后的 WordPress 永久链接 404 错误

php - 使 Wordpress 使用页面而不是类别

php - Wordpress Woocommerce 产品在页面刷新时被添加到购物车

css - 使用 Bootstrap 等并摆脱不需要的 css/函数

php - 从 WC_Product_Variation 获取产品变体

javascript - 为什么 Wordpress 核心数据存储中缺少选择器