我正在运行此查询以打印出我的帖子。它有效,但我想添加一个参数,告诉系统只显示今天或将来发布的帖子!
这里是查询:
$today = getdate();
$year=$today["year"];
$month=$today["mon"];
$day=$today["mday"];
query_posts( $query_string.'order=ASC' .
'&post.status=future,publish' .
'&year='.$year .
'&monthnum='.$month
);
我试着做类似 &post.date = <= $today
的事情但这没有用。
谁能告诉我怎么做?
我的想法是告诉查询只显示发布日期为今天或“小于”今天的帖子。这就是为什么 " <= "
.
最佳答案
$future_args = array(
'post_status' => 'future'
// possibly further query arguments
);
$today = getdate();
$today_args = array(
'year' => $today['year'],
'monthnum' => $today['mon'],
'day' => $today['mday']
// possibly further query arguments
);
$future_query = new WP_Query( $future_args );
$today_query = new WP_Query( $today_args );
while ( $today_query->have_posts() ) :
$today_query->the_post();
// echo something
endwhile;
wp_reset_postdata();
while ( $future_query->have_posts() ) :
$future_query->the_post();
// echo something
endwhile;
wp_reset_postdata();
应该可以了。
关于php - wordpress:只显示今天或 future 的帖子,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15600632/