我有一个名为$speakers的变量,当从下拉列表中选择时,它会显示事件的发言人列表。问题是,如果没有为某个事件选择任何发言者,则所有发言者的列表将显示在该部分中,而不是像应该显示的那样在该部分中显示任何内容,因为没有选择任何内容。以下是代码块:
$speakers = get_post_meta( $post->ID, \'min_webinar_speaker\', false );
$args = array(
\'posts_per_page\' => -1,
\'orderby\' => \'date\',
\'order\' => \'DESC\',
\'include\' => $speakers,
\'post_type\' => \'speaker\',
\'post_status\' => \'publish\',
\'suppress_filters\' => true
);
$speakers = get_posts( $args );
<?php for ($i = 0; $i < count($speakers); $i++) {
$speaker = $speakers[$i];
if ( $i % 2 == 0 ) {
?>
<div class="row">
<?php
}
?>
<article class="subscriber col-sm-6">
<div class="row">
<div class="col-sm-6">
<?php echo get_the_post_thumbnail($speaker->ID, \'thumbnail\'); ?>
</div>
<div class="col-sm-6 subscriber-desc">
<h5 class="moderator"><?php
global $wp_query;
$postid = $wp_query->post->ID;
echo get_post_meta($speaker->ID, \'min_speaker_speaker_role\', true);
wp_reset_query();
?>
</h5>
<h1><?php echo $speaker->post_title; ?></h1>
<?php echo wpautop( $speaker->post_content); ?>
</div>
</div>
</article>
<?php //} ?>
<?php
if ( $i % 2 == 1 || ($i+1) == count($speakers) ) {
?> </div> <!-- test--><?php
}
}?>
如果您有任何关于如何重新处理此代码块以使其正常工作的想法,我们将不胜感激。