【问题标题】:Date range find in wordpress在 wordpress 中查找日期范围
【发布时间】:2015-06-22 13:03:36
【问题描述】:

在 wordpress 中,我只有 publish_date(不是 meta_key)和 meta_key "end_date"

示例:事件从 2015-06-22(publish_date) 到 2015-08-24(meta_ket = "end_date")

现在我想搜索所有事件

  1. (从 2015 年 7 月 5 日至 2015 年 7 月 24 日)

  2. (从 2015-08-05 到 2015-09-25)

    并且必须在示例中显示事件

此代码无效:

$opt = array(
'post_type'     => 'event_info',
'posts_per_page'    =>  '40',
'paged' => $page_num,
'orderby' => 'post_date ID',
'order' => 'DESC',

'relation' => 'OR',

    'meta_query' => array(
        'key' => 'end_date',
        'value' => array('$date_start','$date_end'),
        'compare' => 'BETWEEN',
        'type' => 'numeric'),

    
    'date_query' => array(
        array(
            ......
            'compare'   => 'BETWEEN',
        ),
    ),
    
)
);

元键和 data_query 之间的关系不起作用, 当前的想法是创建 2 个查询,但我不想这样做

【问题讨论】:

    标签: php mysql wordpress date-range


    【解决方案1】:

    试试这个:这里我在 startdate 中添加了时间戳并启用元键

    $chkdt = current_time('timestamp');
    $args = array('post_type'=>'event_info', 'post_status' => 'publish','posts_per_page'=>-1,'orderby' => 'ID','order' => 'DESC', 'meta_query' =>
    array(
    'relation' => 'AND',    
    /******filter start date and End date****************/
    array(
    'key' => 'end_date',
    'value' => $chkdt,
    'compare' => '>=',
    'type' => 'NUMERIC',
    ),
    array(
    'key' => 'start_date',
    'value' => $chkdt,
    'compare' => 'NUMERIC',
    ),
    /******END filter start date and End date****************/
    ),
    ); 
    

    【讨论】:

    • 但是我在元键中没有开始日期,使用了发布日期,我认为这是我的问题...
    猜你喜欢
    • 1970-01-01
    • 2015-10-05
    • 2016-09-22
    • 2016-10-08
    • 2013-03-04
    • 2021-09-07
    • 2017-11-26
    • 1970-01-01
    • 2015-07-22
    相关资源
    最近更新 更多