從當前日期
後鍵入 「事件」 和元鍵名 「date_short_order」
<?php
$today = date("Y/m/d h:i A");
$event_args=array(
'type' => 'event',
'post_status' => 'publish',
'posts_per_page' => 3,
'meta_key' => 'date_short_order', //event_date
'orderby' => 'meta_value_num', //or 'meta_value_num' , 'meta_value'
'meta_query' => array(
array('key' => 'date_short_order',
'value' => $today,
'compare' => '=<',
'type' => 'DATE',
)
),
'order' => 'DESC',
);
$event_my_query = null;
$event_my_query = new WP_Query($event_args);
if($event_my_query->have_posts())
{
while ($event_my_query->have_posts()) : $event_my_query->the_post();
the_title();
endwhile;
}
wp_reset_query($event_my_query);
?>
[獲取過去事件]在URL編碼時被%5B%5D替換。
'['=%5B
''=%5D
post_type=event&posts_per_page=3&post_status=publish&meta_key=date_short_order&orderby=meta_value_num&order=DESC&meta_query[0][key]=date_short_order&meta_query[0][value]=$today&meta_query[0][compare]=<&meta_query[0][type]=DATE
視覺作曲家電網後對過去事件的自定義查詢字符串:
post_type=event&posts_per_page=3&post_status=publish&meta_key=date_short_order&orderby=meta_value_num&order=DESC&meta_query%5B0%5D%5Bkey%5D=date_short_order&meta_query%5B0%5D%5Bvalue%5D=$today&meta_query%5B0%5D%5Bcompare%5D=<&meta_query%5B0%5D%5Btype%5D=DATE
謝謝。但我正在使用visual composer post post自定義查詢選項,這不適用於我的案例。我需要查詢字符串就像我上面張貼。 –
post_type = event&posts_per_page = 3&post_status = publish&meta_key = date_short_order&orderby = meta_value_num&order = DESC&meta_query [0] [key] = date_short_order&meta_query [0] [value] = $ today&meta_query [0] [compare] = DATE –
嘗試以上查詢 –