我试图在一个自定义的"Class“分类的归档页面上显示一个有特色的帖子,并且想要排除带有"work”和"extra“的类别中的帖子。下面并不排除这些类别:
$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;发布于 2020-05-11 21:37:15
我错误地使用了get_cat_ID()函数。使用插件而不是类别名称。
https://stackoverflow.com/questions/61730743
复制相似问题