[英]Date issue in custom post type loop (wordpress)
我正在使用帶有自定義日期字段的自定義帖子類型,以在頁面上顯示游覽日期。 一些帖子同時具有“開始”和“結束”日期(因為它們持續超過一天),而某些帖子僅具有“開始”(因為它們只有一天),並且我希望所有將來或當前的旅行要顯示的日期。
一切運行正常,除非出於某些原因,如果該日期是2016年或更晚,則僅顯示“開始”日期的帖子停止顯示。 對我來說這沒有任何意義!
這是參數:
$today = date('Ymd');
$tour_args = array(
'post_type' => 'tour_date',
'posts_per_page' => -1,
'orderby' => 'meta_value',
'meta_key' => 'tour-date-from',
'order' => 'ASC',
'meta_query' => array(
'relation' => 'OR',
array(
'key' => 'tour-date-from',
'value' => $today,
'compare' => '<=',
),
array(
'key' => 'tour-date-to',
'value' => $today,
'compare' => '>=',
),
),
);
現在解決了。 問題是我需要指定元類型。 我還需要取出“ meta_key”行,因此修改“ orderby”行以查找正確的值。
$today = date('Ymd');
$tour_args = array(
'post_type' => 'tour_date',
'posts_per_page' => -1,
'orderby' => 'tour-date-from',
'order' => 'ASC',
'meta_query' => array(
'relation' => 'OR',
array(
'key' => 'tour-date-to',
'value' => $today,
'compare' => '>=',
'type' => 'NUMERIC'
),
array(
'key' => 'tour-date-from',
'value' => $today,
'compare' => '<=',
'type' => 'NUMERIC'
),
),
);
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.