什么是Wordpress Codex WP Meta Query参数的DATETIME格式?

时间:2018-03-19 10:18:42

标签: wordpress codex

本文档:

https://codex.wordpress.org/Class_Reference/WP_Meta_Query

告诉您可以比较DATETIME值。

WP_Meta_Query的DATETIME格式是什么?

1 个答案:

答案 0 :(得分:1)

从Wordpress文档中,您似乎应该使用以下字符串格式:Y-m-d H:i:s

因此元查询可能是:

$meta_query_args = array(
    'relation' => 'OR', // Optional, defaults to "AND"
    array(
        'key'     => 'field_key_with_datetime',
        'value'   => '2018-03-19 08:23:25', // Y-m-d H:i:s format
        'compare' => '=',
        'type'    => 'DATETIME'
    )
);
$meta_query = new WP_Meta_Query( $meta_query_args );

您可以使用wordpress current_time函数获取当前DATETIME

$meta_query_args = array(
    'relation' => 'OR',
    array(
        'key'     => 'field_key_with_datetime',
        'value'   => current_time( 'mysql' ), // will return something like '2018-03-19 08:23:25'
        'compare' => '=',
        'type'    => 'DATETIME'
    )
);
$meta_query = new WP_Meta_Query( $meta_query_args );

来源:https://developer.wordpress.org/reference/functions/current_time/

相关问题