在这种情况下,获取职位的期限,然后计算其中的职位数量。为WP\\u查询设置一个if条件以进行检查,该术语中的posts为零或大于零,然后为$args。
<?php
global $post;
$term = get_term( \'hometwo\', \'Presenter-type\' );
$posts_in_term = $term->count;
?>
<?php
if($posts_in_term > 0 ){
$args = array(
\'post_type\' => \'presenters\',
\'posts_per_page\' => 1,
\'tax_query\' => array(
array (
\'taxonomy\' => \'Presenter-type\',
\'field\' => \'slug\',
\'terms\' => \'hometwo\'
)
)
);
}
else{
$args = array() //your default query;
}
$query = new WP_Query ( $args );
?>
<?php if ($query->have_posts()) : ?>
<?php while ($query->have_posts()) : $query->the_post(); ?>
<a href="<?php the_permalink(); ?>">
<?php the_post_thumbnail(); ?>
<h3><?php the_title(); ?></h3>
<p><?php the_excerpt(); ?></p></a>
<?php endwhile; ?>
<?php else : ?>
<?php endif; ?>
<?php wp_reset_query(); ?>