php - wordpress:只显示今天或 future 的帖子

标签 php wordpress

我正在运行此查询以打印出我的帖子。它有效,但我想添加一个参数,告诉系统只显示今天或将来发布的帖子!

这里是查询:

$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供引用。

关于php - wordpress:只显示今天或 future 的帖子,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15600632/

相关文章:

php - 缓存策略,什么时候缓存变得毫无意义?

php - WordPress MySQL 查询失败

javascript - 数据库数据重新排列/转换的最佳实践?

ajax - 使用分类法过滤自定义帖子 - 添加全部按钮

php - 显示列名

php - 连接失败 : 0 push notification

javascript - jquery jquery.RotateImageMenu 未捕获语法错误 : Unexpected end of input

linux - .htaccess:如何美化我的 URL 并删除结尾的正斜杠?

php - Wordpress 响应式主题, Logo 在浏览器中显示不同

html - 无法修改 Wordpress 主题的边距