我试图在一个自定义的 "类 "分类的存档页面上显示一个特色文章,并希望排除带有 "工作 "和 "额外 "的类别中的文章。下面的方法并没有排除这些类别。
$class = get_queried_object(); // Get the current class
$current_class = $class->term_id; //Get the current class ID
$extras_cat = get_cat_ID( 'extra' );
$class_work_cat = get_cat_ID( 'work' );
$args = array(
'tax_query' => array(
array(
'taxonomy' => 'filmbites_class',
'field' => 'term_id',
'terms' => $current_class,
),
),
'category__not_in' => array( $extras_cat, $class_work_cat ),
'posts_per_page' => 1
);
$posts= new WP_Query($args);
if($posts->have_posts()) :
while($posts->have_posts()) :
$posts->the_post();
$featured_post = get_the_ID(); //get the ID of the post to be featured
endwhile;
endif;
我使用的是 get_cat_ID()
功能错误。用slugs代替类别名称。