我正在运行此查询以打印我的帖子。它可以工作,但我想添加一个参数,告诉系统只显示从今天起或将在未来发布的帖子!
以下是查询:

$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();

应该这样做。
参考codex article on the WP_Query class

10-07 12:53
查看更多