【发布时间】:2017-09-07 08:04:25
【问题描述】:
基本上想用 term = 艺术显示第一个帖子,如果不存在则显示带有 term = guides 的帖子。
这是我的两个论点,我一直在尝试在循环外使用 has_term 但不起作用。
<?php
if ( has_term( 'arts', 'postkicker' )){
$args=array(
'post_type' => 'post',
'taxonomy' => 'postkicker',
'term' => 'arts',
'orderby' => 'date',
'order' => 'DESC'
);
} else {
$args=array(
'post_type' => 'post',
'taxonomy' => 'postkicker',
'term' => 'guides',
'orderby' => 'date',
'order' => 'DESC'
);
}
$my_query = new WP_Query($args);
if ( $my_query->have_posts() ) :
while ( $my_query->have_posts() ) : $my_query->the_post();
the_title( sprintf( "<h1><a href='%s' rel='bookmark'>", esc_url( get_permalink() ) ), "</a></h1>" );
endwhile;wp_reset_postdata();endif;
?>
有什么建议吗?我需要在循环中移动我的 has_term 吗? 提前致谢!
【问题讨论】:
标签: php wordpress conditional