我正在使用PHP 7.3.5
和wordpress 5.2.x
。
我有以下查询,该查询提供了大于today
的所有内容:
$today = new DateTime();
$timestToday = $today->getTimestamp();
try {
$args = array(
'post_type' => 'Calendar-Events',
'posts_per_page' => -1, // add -1 here for all posts
'post_status' => 'publish',
'meta_key' => 'timestamp',
//'orderby' => 'meta_value',
//'order' => 'ASC',
'meta_query' => array(
array(
'key' => 'timestamp',
'compare' => '>=',
'value' => $timestToday,
),
),
);
$upcomingEvents = new WP_Query($args);
任何建议如何通过将来只返回+7 days
是什么来限制我的结果集?
感谢您的答复!
答案 0 :(得分:3)
$today = new DateTime();
$Today = $today->getTimestamp();
$Futuredate = date("Ymd", strtotime($Today."+7 days"));
try {
$args = array(
'post_type' => 'Calendar-Events',
'posts_per_page' => -1, // add -1 here for all posts
'post_status' => 'publish',
'meta_key' => 'timestamp',
//'orderby' => 'meta_value',
//'order' => 'ASC',
'meta_query' => array(
array(
'key' => 'event_start_date',
'value' => array( $Today, $Futuredate ),
'compare' => 'BETWEEN',
'type' => 'DATE'
),
),
);
$upcomingEvents = new WP_Query($args);
为使您更好地理解,请访问此link