我想出了一种使用两个post查询的方法。第一个循环遍历循环,并将1添加到名为$counttest的变量中。然后它回显该值并将其重置为0,以开始下一个日期的计数。
这可能不是最有效的做事方式。如果有人知道更好的方法,请告诉我。
<?php
$today = date("Y-m-d");
$todaytext = date("l");
for ($i=0; $i<7; $i++){
$thedate = strtotime ( \'+\'.$i.\' day\' , strtotime ( $today ) ) ;
$thedate = date ( \'Y-m-d\' , $thedate );
$thedatetext = strtotime ( \'+\'.$i.\' day\' , strtotime ( $todaytext ) ) ;
$thedatetext = date ( \'l\' , $thedatetext );
$args = array(
\'post_type\' => \'event\',
\'orderby\' => \'meta_value\',
\'order\' => \'asc\',
\'meta_query\' => array(
\'relation\' => \'OR\',
array(
\'key\' => \'opening_time\',
\'value\' => $thedate,
\'compare\' => \'LIKE\',
\'type\' => \'DATE\'
),
array(
\'key\' => \'artist_talk_time\',
\'value\' => $thedate,
\'compare\' => \'LIKE\',
\'type\' => \'DATE\'
)
)
);
$event_query = new WP_Query( $args );
if ($event_query->have_posts()) : while ($event_query->have_posts()) : $event_query->the_post();
if (get_post_meta($post->ID,\'opening_time\', true)==$thedate)
{ $counttest++;}
if (get_post_meta($post->ID,\'film_time\', true)==$thedate)
{ $counttest++;}
if (get_post_meta($post->ID,\'artist_talk_time\', true)==$thedate)
{ $counttest++;}
endwhile;
echo $counttest;
if ($counttest>=2){
echo \' Events \';
} // end if ($totalevents>=2) function
if ($counttest<2){
echo \' Event \';
}
echo $count;
if ($thedate==$today){echo \'Today\';}
if ($thedate>$today){
echo $thedatetext;}
echo \'<br>\';
endif;
$counttest=0;
if ($event_query->have_posts()) : while ($event_query->have_posts()) : $event_query->the_post();
if (get_post_meta($post->ID,\'opening_time\', true)==$thedate)
{
?>
<a href="<?php the_permalink() ?>" title="<?php the_title(); ?>"><?php the_title(\'<h2>\', \'</h2>\'); ?></a>
<h2>Opening Reception</h2>
<?php
echo get_post_meta($post->ID,\'opening_time\', true);
}
if (get_post_meta($post->ID,\'artist_talk_time\', true)==$thedate){ ?>
<a href="<?php the_permalink() ?>" title="<?php the_title(); ?>"><?php the_title(\'<h2>\', \'</h2>\'); ?></a>
<h2> Artist Talk </h2>
<?php
echo get_post_meta($post->ID,\'artist_talk_time\', true);
}
endwhile;
endif;
rewind_posts();
}
?>