我正在为一个广播网站编写一个直播节目框,以显示谁在广播,谁是下一个。我一直在使用get\\u post函数根据类别(在本例中为一周中的某一天)检索帖子,以及为了显示现在应该直播的节目,该节目是否尚未到达其结束时间(自定义字段)。
然而,它有一个转折点,有时会起作用,并且会在其他地方显示错误的节目标题。你知道我哪里做错了吗?
代码如下,请访问http://livewire1350.com 看到它在起作用。
编辑:我已经根据@CharlesClarkson的评论修改了代码,但仍然存在一个问题。出于调试目的,我将代码设置为按时间升序显示整个帖子列表,但在0:00到9:00之间,它开始从22:30降序到18:00,然后在9:00以升序方式继续,直到17:00(如下所示)。你知道为什么会这样吗?
现场:9:29
0:00
现场:9:29
22:30
现场:9:29
21:00
现场:9:29
19: 30个
现场:9:29
18: 00
现场:9:29
9: 00
现场:9:29
10: 30个
现场:9:29
12: 00
现场:9:29
12: 30个
现场:9:29
14: 00
现场:9:29
15: 30个
现场:9:29
17: 00
<?php
date_default_timezone_set(\'Europe/London\');
$now = time();
$time = date( \'G:i\');
$day_of_the_week = date( \'w\', $now );
// S M T W T F S
$day_of_the_week_categories = array( 17, 18, 12, 13, 14, 15, 16 );
$day_of_the_week = date( \'w\' );
// The Query
$the_query = new WP_Query( array(
\'cat\' => $day_of_the_week_categories[ $day_of_the_week ],
\'posts_per_page\' => -1,
\'offset\' => 0,
\'orderby\' => \'meta_value_num\',
\'order\' => \'DESC\',
\'meta_query\' => array(
array(
\'key\' => \'Start_Time\',
\'type\' => \'TIME\',
)
)
)
);
// The Loop
if ( $the_query->have_posts() ) :
while ( $the_query->have_posts() ) : $the_query->the_post();?>
<div class="liveshow">
<div id="livebanner">
<div id="showwrap">
<div id="showdetails">
<div id="onair">
<h3>LIVE: <?php echo $time ?></h3><p class="showname"><a href="<?php the_permalink() ?>"><?php $short_title = substr(the_title(\'\',\'\',FALSE),0,18);
echo get_post_meta( get_the_ID(), \'Start_Time\', true );
?></p>
</div>
<?php
endwhile;
endif;
?>