Php Wordpress中今天的自定义帖子查询
我在模板中使用下面给出的post查询。但所有直播体育项目的帖子都显示在模板中。我只想要今天的帖子。我现在能做什么Php Wordpress中今天的自定义帖子查询,php,html,css,wordpress,Php,Html,Css,Wordpress,我在模板中使用下面给出的post查询。但所有直播体育项目的帖子都显示在模板中。我只想要今天的帖子。我现在能做什么 <blink> $today = getdate(); $args = array( 'posts_per_page' => -1, 'post_type'=> 'live-sports-items', 'date_query' => array( array(
<blink>
$today = getdate();
$args = array(
'posts_per_page' => -1,
'post_type'=> 'live-sports-items',
'date_query' => array(
array(
'year' => $today['year'],
'month' => $today['mon'],
'day' => $today['mday'],
),
),
);
$my_query = new WP_Query($args);
while ($my_query->have_posts()) : $my_query->the_post();?>
<li><?php the_title(); ?> <br /></li>
<?php endwhile; ?>
</blink>
编辑:
尝试改变
$args = array(
'posts_per_page' => -1,
'post_type'=> 'live-sports-items',
'date_query' => array(
array(
'year' => $today['year'],
'month' => $today['mon'],
'day' => $today['mday'],
),
),
);
与
:-如果有帮助,请告诉我。刚才我编辑了上面的代码。您做了哪些更改?您使用的是哪个Wordpress版本?我已经在Wordpress安装中测试了您的代码,并且运行正常。它对你不起作用的原因可能是因为没有今天的帖子或者post_类型的直播体育项目是不正确的。但是,您可以尝试直接在WP_查询中传递变量。示例:$query=new WP_query'year=2014&monthnum=11&day=29';
$args = array(
'posts_per_page' => -1,
'post_type'=> 'live-sports-items',
'year' => $today['year'],
'monthnum' => $today['mon'],
'day' => $today['mday'],
);